+ Reply to Thread
Results 1 to 3 of 3
This is a discussion on Update Contact within the Salesforce Coding Discussions forums, part of the Salesforce category; Hey Mike, I'm having some problems with the new(er) API. I'm using
  1. #1
    ncee is offline Junior Member
    Join Date
    Oct 2007
    Posts
    14

    Angry Update Contact

    Hey Mike,

    I'm having some problems with the new(er) API. I'm using the API with the copyright of 2007. I'm trying to make a Web-to-contact form. I'm getting stuck with trying to update a contact's info. Here's my code:

    PHP Code:
        ...
        require_once (
    'soapclient/SforcePartnerClient.php');
        
        
    $mySforceConnection = new SforcePartnerClient();
        
    $mySoapClient $mySforceConnection->createConnection("partner.wsdl");
        
    $mylogin $mySforceConnection->login($username$final_password);

        
    $query "Select Id, Email From Contact WHERE Email = '".$_POST['Email']."'";
        
    $queryResult $mySforceConnection->query($query);
        
    $records $queryResult->records;    

        
    //Get rig of NULL values
        
    foreach($_POST as $field => $value)
            if(
    strlen(trim($value)) == 0)
                unset(
    $_POST[$field]);

        if(
    sizeof($records) > 0)
        {
            foreach (
    $records as $record
            {
                
    $sObject = new SObject($record);
                
    $contactEmail $sObject->fields->Email;
                
    $contactID $sObject->Id;
            }

            
    $sObject = new sObject();
            
    $sObject->type 'Contact';        
            
    $sObject->Id $contactID;

            
    $sObject->field $_POST;
            
            
    //Output for debugging
            
    print_r($sObject);
            
    print_r($mySforceConnection->update(array($sObject)));
        } 
    Here is the output:

    SObject Object ( [type] => Contact [fields] => [Id] => 0025000000pcAdfWEL [field] => Array ( [FirstName] => John [LastName] => Smith [email] => john.smith@something.net [School_Name__c] => LSU [title] => Web Developer [MailingStreet] => 465 12th Ave. N [MailingCity] => Somewhere [MailingState] => LA [MailingPostalCode] => 98754 [Mail_Opt_In__c] => true [notes__c] => This is a test. ) ) stdClass Object ( [id] => 0025000000pcAdfWEL [success] => 1 )

    The problem is that the record in salesforce does not update. Any ideas what I'm missing?

  2. #2
    ncee is offline Junior Member
    Join Date
    Oct 2007
    Posts
    14
    Figured it out...

    PHP Code:
        ...
        require_once (
    'soapclient/SforcePartnerClient.php');
        
        
    $mySforceConnection = new SforcePartnerClient();
        
    $mySoapClient $mySforceConnection->createConnection("partner.wsdl");
        
    $mylogin $mySforceConnection->login($username$final_password);

        
    $query "Select Id, Email From Contact WHERE Email = '".$_POST['Email']."'";
        
    $queryResult $mySforceConnection->query($query);
        
    $records $queryResult->records;    

        
    //Get rig of NULL values
        
    foreach($_POST as $field => $value)
            if(
    strlen(trim($value)) == 0)
                unset(
    $_POST[$field]);

        if(
    sizeof($records) > 0)
        {
            foreach (
    $records as $record
            {
                
    $sObjects = new SObject($record);
                
    $contactEmail $sObjects->fields->Email;
                
    $contactID $sObjects->Id;
            }
            unset(
    $sObjects);

            
    $_POST['Id'] = $contactID;
            
    $sObject = new SObject();
            
    $sObject->fields $_POST;
            
    $sObject->type 'Contact';
            
            
    print_r($sObject);
            
    print_r($mySforceConnection->update(array ($sObject)));        

        } 

  3. #3
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    Sorry I could not get here fast enough lol, Great job figuring it out man!


    ~Mike

+ 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.2