Home PHP Update the Salesforce Contact Record using PHP

Update the Salesforce Contact Record using PHP

In PHP Project Folder (PHP_SFDC), Create a new File called updateRecord.php file and save it to www/Htdocs/PHP_SFDC/updateRecord.php path

<?php
ini_set(“soap.wsdl_cache_enabled”, “0”);

// PHP Tool Kit class scripts to login to Salesforce Org
require_once (‘../includes/soapclient/SforcePartnerClient.php’);
require_once (‘../includes/soapclient/SforceHeaderOptions.php’);

// Salesforce Login information
$wsdl = ‘partner.wsdl.xml’;    // PARTNER WSDL FILE PATH
$userName = “salesforce username”;
$password = “salesforce password”; // PASSWORD SHOULD BE COMBINATION OF “PASSWORD + SECURITY TOKEN”, if it’s a Developer ORG.

// Process of logging on and getting a salesforce.com session
$client = new SforcePartnerClient();
$client->createConnection($wsdl);
$loginResult = $client->login($userName, $password);

//Then perform to Update Your Data to Salesforce Contact Object
$fieldsToUpdate = array (
‘FirstName’ => ‘TheBlogReaders.com 1’,
‘City’ => ‘BANGALORE’,
‘Country’ => ‘INDIA’
);
$sObject1 = new SObject();
$sObject1->fields = $fieldsToUpdate;
$sObject1->type = ‘Contact’;
$sObject1->Id = $UPDATEID1; // YOU NEED TO MENTION THE UDATE FIELD ID

$fieldsToUpdate = array (
‘FirstName’ => ‘TheBlogReaders.com 2’,
‘City’ => ‘CHENNAI’,
‘Country’ => ‘INDIA’
);
$sObject2 = new SObject();
$sObject2->fields = $fieldsToUpdate;
$sObject2->type = ‘Contact’;
$sObject2->Id = $UPDATEID2; // YOU NEED TO MENTION THE UDATE FIELD ID
$sObject2->fieldsToNull = array(‘Fax’, ‘Email’);

$response = $mySforceConnection->update(array ($sObject1, $sObject2));
print_r($response);

} catch (Exception $e) {
print_r($mySforceConnection->getLastRequest());
echo $e->faultstring;
}
?>

SAMPLE OUTPUT:
Array
(
[0] => stdClass Object
(
[id] => 0035000000VbmTREAV
[success] => 1
)
[1] => stdClass Object
(
[id] => 0035000000VbGHTEAV
[success] => 1
)
)

You may also like

Leave a Comment