Obama '08

               
   

Go Back   Mike Simonds > Salesforce > Salesforce Coding Discussions

This is a discussion on Update Contact Description within the Salesforce Coding Discussions forums, part of the Salesforce category; I am new to salesforce api, but not to PHP. I currently

Reply
 
LinkBack Thread Tools Rate Thread
  #1  
Old 04-18-2008, 05:57 PM
smit1626
Guest
 
Posts: n/a
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2  
Old 04-21-2008, 08:03 AM
Administrator
 
Join Date: May 2007
Posts: 248
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
php salesforce scripts, queries in salesforce, salesforce contacts

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump



Powered by vBulletin


SEO by vBSEO 3.2.0 RC8 ©2008, Crawlability, Inc.

1 2 3 4 5