+ Reply to Thread
Results 1 to 7 of 7

Thread: How do you create a new Task via the API

  1. #1
    benbac is offline Junior Member
    Join Date
    Aug 2009
    Posts
    9

    How do you create a new Task via the API

    I was wondering if anyone was able to essentially log a task to a custom object via the API. I have a custom Lead__c object that I'd like to log tasks to it's activities. I'm using the partner api, do i create the Task object like I create any other object?

    Any information would be much appreciated?

  2. #2
    benbac is offline Junior Member
    Join Date
    Aug 2009
    Posts
    9
    Never mind, I ended up just trying what I posted and yes it's created same as any other object.

    (mike feel free to delete this post)

  3. #3
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    I am glad that you figured it out and there is no need to delete it, someone may ask you for help sometime with this.

    ~Mike

  4. #4
    cewyattjr is offline Junior Member
    Join Date
    Nov 2009
    Posts
    2

    Would love an example

    I'm actually struggling with this at the moment, I have other API functions (create/upsert) working well, but when I try and create a new task, I'm getting an error: Invalid SOAP header in SforceBaseClient.php on line 273.

    I get this error regardless of whether I use the Partner or Enterprise client. I wonder if I need to use a specific header option? I used this in the past with ol' NuSOAP without any issue.

    eg of my code below that is throwing the error (authentication works fine of course).

    Thanks so much!

    Chuck
    PHP Code:
    require_once('soapclient/SforceEnterpriseClient.php');

    /**
     * explicitly turn off WSDL caching (toggling this makes no difference)
    */
    ini_set('soap.wsdl_cache_enabled'0);

    // instantiate a new Salesforce Enterprise object
    $crmHandle = new SforceEnterpriseClient();

    // instantiate a SOAP connection to Salesforce
    try {
      
    $crmHandle->createConnection(SALESFORCE_WSDL);
    } catch (
    Exception $e) {
      
    // handle exception - did you set the WSDL path above?
      // we may also be in a Salesforce outage right now
    }

    // log in to Salesforce
    try {
      
    $crmHandle->login(SALESFORCE_USERSALESFORCE_PASS SALESFORCE_TOKEN);
    } catch (
    Exception $e) {
      
    // handle exception - did you modify the credentials above to your own?
    }


    // create our task based on SFID as WhoID:

    $task = array();
    $task['WhoID'] = 'xxxxxxxxxxxxxxxxx';
    $task['Description'] = 'the latest activity detail goes here';
    $task['Status'] = 'Completed';
    $task['Subject'] = 'Trial activity';
    $task['OwnerID'] = 'xxxxxxxxxxxxxxxxx';

    // create the task
    $result $crmHandle->create(array($task), 'Task'); 

  5. #5
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    Chuck,

    I will take a look at this. I think that I actually have a demo task script somewhere on my server, but need to look for it.

    I am getting ready to head to dreamforce and do not know when I will be able to look for it, probably tomorrow or Wednesday!!


    ~MIKE

  6. #6
    cewyattjr is offline Junior Member
    Join Date
    Nov 2009
    Posts
    2

    My bad... this example works!

    I think I had a bad copy/paste in my security token. For future reference, this below works!

    PHP Code:
    define('SALESFORCE_USER''username@domain.com');
    define('SALESFORCE_PASS''**********');
    define('SALESFORCE_TOKEN''abcdefj123890');
    define('SALESFORCE_WSDL''enterprise.wsdl.xml');


    require_once(
    'soapclient/SforceEnterpriseClient.php');


    // instantiate a new Salesforce Enterprise object
    $crmHandle = new SforceEnterpriseClient();


    // instantiate a SOAP connection to Salesforce
    try {
      
    $crmHandle->createConnection(SALESFORCE_WSDL);
    } catch (
    Exception $e) {
      
    // handle exception - did you set the WSDL path above?
      // we may also be in a Salesforce outage right now
    }


    // log in to Salesforce
    try {
      
    $crmHandle->login(SALESFORCE_USERSALESFORCE_PASS SALESFORCE_TOKEN);
    } catch (
    Exception $e) {
      
    // handle exception - did you modify the credentials above to your own?
    }

    // create our task based on SFID as WhoID:

    $task = array();
    $task['WhoID'] = 'xxxxxxxxSFIDgoesherexxxxx';
    $task['Description'] = 'the latest activity detail goes here';
    $task['Status'] = 'Completed';
    $task['Subject'] = 'Trial activity';
    $task['OwnerID'] = 'xxxxleadOWNERidgoesherexxx';


    // create the task
    // $task must be wrapped in an array, as create() can create
    // many objects with a single API call
    $result $crmHandle->create(array($task), 'Task');

    var_dump($result ); 

  7. #7
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    Glad you figured it out

+ 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