+ Reply to Thread
Results 1 to 2 of 2

Thread: Update Contact Description

  1. #1
    smit1626 Guest

    Update Contact Description

    I am new to salesforce api, but not to PHP.

    I currently have a client that uses SF and wishes to track customer activity on their website. I do this on their current website using MySQL and it works great. Now they would like to store the activity in SF. They have decided to go with placing the information in the Description field on Contacts.

    My following code:
    PHP Code:
    $query "SELECT Id, Description,FirstName, LastName from Contact where Email='$email_address'";
    $queryResult $mySforceConnection->query($query);

     if (
    $queryResult->size 0) {
    $records $queryResult->records;
    foreach (
    $records as $record) {
      
    $sObject = new SObject($record);
      echo 
    "Id = ".$sObject->Id;
      echo 
    "First Name = ".$sObject->fields->FirstName;
      echo 
    "Last Name = ".$sObject->fields->LastName;

      
    $sObjectContact=new sObject();
      
    $sObjectContact->type='Contact';
      
    $sObjectContact->Id=$sObject->Id;
      
    $sObjectContact->fields["Description"]=$sObject->fields->Description ';Document download from website:' $redirect_file ' on $date';
     
    // print_r ($sObjectContact);
      
    $result=$mySforceConnection->update($sObjectContact);
     
    // print_r($result);
      
    if($result->success){
        echo 
    "good";
       }else{
        echo 
    "bad";
     }
    }


    It seems to return a successful result, but it does not update the contact info inside SF.

    What am I doing wrong?

  2. #2
    Join Date
    May 2007
    Posts
    502
    Blog Entries
    3
    smit1626

    You had a few small mistakes in your code, but that may have been done when you posted it. I revamped a little, try this code and see if it works for you. I tested it on my localhost and it works fine against my salesforce developer organization or instance:


    PHP Code:
    <?php
    ini_set
    ("soap.wsdl_cache_enabled","0");
    $username 'me@email.com';
    $password 'password';
    $date date("m/d/y");

    require_once (
    './soapclient/SforcePartnerClient.php');
    $mySforceConnection = new SforcePartnerClient();
    $mySoapClient $mySforceConnection->createConnection("./soapclient/partner.wsdl.xml");
    $mylogin $mySforceConnection->login($username,$password);
    $email_address "bob@smith.com";
    $redirect_file 'test file';
    try
    {
        if (
    $mylogin)
        {
            
    $query "SELECT Id, Description,FirstName, LastName from Contact where Email='$email_address'";

            
    $response $mySforceConnection->query($query);
            
    $queryResult = new QueryResult($response);

            foreach (
    $queryResult->records as $record)
            {
                echo 
    '<pre>' print_r($record,true) . '</pre>';
                
    $sObjectContact = new sObject();
                
    $sObjectContact->type 'Contact';
                
    $sObjectContact->Id $record->Id;
                
    $sObjectContact->fields = array('Description' => $record->fields->Description ';Document download from website:' $redirect_file ' on ' $date);
                
    print_r($sObjectContact);
                
    $result $mySforceConnection->update(array($sObjectContact));
                
    // print_r($result);
                
    if ($result->success)
                {
                    echo 
    "good";
                }
                else
                {
                    echo 
    "bad";
                }
            }


        }
        else
        {
            echo 
    "crap, something is wrong";
        }
    }
    catch (
    exception $e)
    {
        echo 
    $mySforceConnection->getLastRequest();
        echo 
    $mySforceConnection->getLastRequestHeaders();
        echo 
    '<pre>' print_r($e,true) . '</pre>';
    }
    ?>
    I had to set some local variables to test your code. If you compare the two scripts next to each other, you will see a few small differences, but it was not that much

    Hope that helps and you should register here if you are going to be working on salesforce applications

    let me know if you have any other questions

    ~Mike

+ Reply to Thread

Tags for this 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.0 RC1 PL1