The object to update or insert a new calendar event is the "Event" object in salesforce
There are 4 required fields that need to be inserted in order for the event to be added to your instance of Salesforce.
- Assigned To
- Subject
- Start (date and time)
- End (date and time)
Those API field names are
- Owner Id
- Subject
- StartDateTime
- EndDateTime
Remember that Salesforce times are all set to GMT, so you have to account for that. Since my time is set to -6 GMT, I have to adjust my code for that:
PHP Code:
$mystuff = array('OwnerId' => '00550000000wI2LAAU', // Assigned To
'Subject' => 'PHP Event Addidtion Test 2', //Subject
'StartDateTime' => '2008-08-05T12:00:00.000Z', //Start time of event
'EndDateTime' => '2008-08-05T13:00:00.000Z'); //End time of event **ALL TIMES ARE GMT, REMEMBER TO ACCOUNT FOR THIS****
An example of this would be: If you were on Pacific Standard Time (-8 GMT) and had a meeting starting at 10 AM on August 10th, your StartDateTime would be:
2008-08-10T18:00:00.000Z
Here is a script that works for adding an event to a calendar
Now I am not sure if you can update it(change it)
PHP Code:
<?php
ini_set("soap.wsdl_cache_enabled","0");
require_once ('./soapclient/SforcePartnerClient.php');
require_once ('./soapclient/SforceHeaderOptions.php');
$mystuff = array('OwnerId' => '00550000000wI2LAAU', // Assigned To
'Subject' => 'PHP Event Addidtion Test 2', //Subject
'StartDateTime' => '2008-08-05T12:00:00.000Z', //Start time of event
'EndDateTime' => '2008-08-05T13:00:00.000Z'); //End time of event **ALL TIMES ARE GMT, REMEMBER TO ACCOUNT FOR THIS****
//clean User to allow changing of characters to XML
$mystuff = array_map('htmlspecialchars',$mystuff);
//try to add User from from array
try
{
//salesforce login and wsdl
$wsdl = './soapclient/partner.wsdl.xml';
$userName = "me@email.com"; // change this to a valid email
$password = "password"; // change this to a valid password
//connect to salesforce
$client = new SforcePartnerClient();
$client->createConnection($wsdl);
$loginResult = $client->login($userName,$password);
$sObject = new sObject();
$sObject->type = 'Event';
$sObject->fields = $mystuff;
//this part adds the contact to salesforce
$result = $client->create(array($sObject));
if ($result->success)
{
echo "A new Calendar event has been added to your instance of Salesforce with an Id of ".$result->id."<br />";
echo "**************** ALL DONE ****************<br />";
exit;
}
else
{
$errMessage = $result->errors->message;
echo $errMessage;
}
}
catch (exception $e)
{
// This is reached if there is a major problem in the data or with
// the salesforce.com connection. Normal data errors are caught by
// salesforce.com
echo '<pre>'.print_r($e,true).'</pre>';
return false;
exit;
}
?>
Hope this helps!
~Mike
Bookmarks