+ Reply to Thread
Results 1 to 9 of 9

Thread: Adding an Event to the Calendar

  1. #1
    asugrad is offline Junior Member
    Join Date
    Jul 2008
    Posts
    4

    Adding an Event to the Calendar

    I need to be able to add an event to the calendar on the dashboard through the API. Has anyone had any experience doing this? Any help would be much appreciated. (Thanks, Mike for letting me know that this can be done.) I will keep plowing through the documentation and keep testing. If I come up with a solution in the meantime, I will post it.

    Cheers.

  2. #2
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    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

  3. #3
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    Here is a screen shot of the event addition to Salesforce using that same script that I posted previously:
    Attached Thumbnails Attached Thumbnails Adding an Event to the Calendar-event_addition.jpg  

  4. #4
    asugrad is offline Junior Member
    Join Date
    Jul 2008
    Posts
    4

    Perfect!

    Thanks, Mike. It is so much easier to understand with an example. Cheers.

  5. #5
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    Glad that it shows you what can be done and glad to help

    Thanks for joining asugrad

    ~Mike

  6. #6
    asugrad is offline Junior Member
    Join Date
    Jul 2008
    Posts
    4

    Oops

    Hey Mike,
    I am getting the following error while testing:
    Event: bad field names on insert/update call: EndDateTime, StartDateTime

    Can you advise?

    Thanks again.

  7. #7
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    I do not know why you would be getting that error.

    Those field names are setup and defaulted by Salesforce

    I checked my production, sandbox, and development account and all the field names are the same in all 3 instances.

    Sorry man, that script that i posted was an exact duplicate of a working script that added an even (as you saw)

    I would login to the data loader (if you have it), select the Event object to extract, and check the field names to see if they are the same

    I think you will find that they are, but please do check

    ~Mike

  8. #8
    asugrad is offline Junior Member
    Join Date
    Jul 2008
    Posts
    4

    Success!

    You were right. I dumped out the data structure using your tool and a couple of the column names were different in the Event object. Here is what I changed:

    $mystuff = array('OwnerId' => 'MYOWNERID', // Assigned To
    'Subject' => 'PHP Event Addition Test ', //Subject
    'ActivityDateTime' => '2008-08-05T12:00:00.000Z', //Start time of event**ALL TIMES ARE GMT, REMEMBER TO ACCOUNT FOR THIS****
    'DurationInMinutes' => 60);
    Attached Thumbnails Attached Thumbnails Adding an Event to the Calendar-salesforce-enterprise-edition_1217962633308.png  

  9. #9
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    So it worked!!

    Good man!! outstanding!

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO 3.5.1