Friday, November 7, 2014

Salesforce PHP intregration



  1. Generate WSDL from your Salesforce organization
  2. Download PHP Class library SoapClient
  3. Requirements
    1. PHP 5.x
    2. SOAP Enabled
    3. SSL Enabled
    4. cURL Enabled
    5. OpenSSL Enabled
  4. PHP Code
  5. More information PHP_Toolkit_20.0


// Salesforce Credential
define("USERNAME", "<<Salesforce UserName>>");
define("PASSWORD", "<<SalesforcePassword>>");
define("SECURITY_TOKEN", "<<SalesforcePassword>>");

   require_once ('soapclient/SforceEnterpriseClient.php');
  $mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

Create Account

 $a = new stdClass();
$a ->BillingCity='city';
$a ->BillingCountry='country';
$a ->BillingPostalCode='postcode';
$a ->BillingState='state';
$a ->BillingStreet='address_1';
$a->Phone='phone';
$a ->Name='Companyname';
$a ->RecordTypeId=$AccountRecordType;
$a ->ShippingCity='ShippingCity';
$a ->ShippingCountry='ShippingCountry';
$a ->ShippingPostalCode='ShippingPostalCode';
$a ->ShippingState='ShippingState';
$a ->ShippingStreet='ShippingStreet';
$response = $mySforceConnection ->create(array($a), 'Account');
//print_r($response);
$AccountId = $response[0]->id;
   echo "Account Id". $AccountId ."<br/>";
Update Account
$a = new stdClass();
$a ->Id='0035000000o1afRAAQ';
$a ->BillingCity='city';
$a ->BillingCountry='country';
$a ->BillingPostalCode='postcode';
$a ->BillingState='state';
$a ->BillingStreet='address_1';
$a->Phone='phone';
$a ->Name='Companyname';
$a ->RecordTypeId=$AccountRecordType;
$a ->ShippingCity='ShippingCity';
$a ->ShippingCountry='ShippingCountry';
$a ->ShippingPostalCode='ShippingPostalCode';
$a ->ShippingState='ShippingState';
$a ->ShippingStreet='ShippingStreet';
$response = $mySforceConnection ->upsert(array($a), 'Account');
//print_r($response);
 $AccountId = $response[0]->id;
    echo "Account Id". $AccountId ."<br/>";

Upsert Account

$a = new stdClass();
$a ->Id='0035000000o1afRAAQ';
$a ->BillingCity='city';
$a ->BillingCountry='country';
$a ->BillingPostalCode='postcode';
$a ->BillingState='state';
$a ->BillingStreet='address_1';
$a->Phone='phone';
$a ->Name='Companyname';
$a ->RecordTypeId=$AccountRecordType;
$a ->ShippingCity='ShippingCity';
$a ->ShippingCountry='ShippingCountry';
$a ->ShippingPostalCode='ShippingPostalCode';
$a ->ShippingState='ShippingState';
$a ->ShippingStreet='ShippingStreet';
$response = $mySforceConnection ->upsert(array($a), 'Account');
//print_r($response);
 $AccountId = $response[0]->id;
 $isCreated= $response[0]->created;  //To Check Account is to be update or Created
    echo "Account Id". $AccountId ."<br/>";

Select records


$query="Select p.Id from PricebookEntry p where CurrencyIsoCode='".$currency."'";
 echo $query;
$response = $mySforceConnection->query($query);
echo $response->records[0]->Id.'<br/>';

No comments:

Post a Comment