Skip navigation

Blog > SalesForce web integration

SalesForce is an online Customer Relationship Manager (CRM) and business application tool. I will not go into more detail about SalesForce as there website explains what they do.

At Bluelinemedia we have had a few clients who use SalesForce mainly for its CRM services. The CRM database will usually contain information such as customer details, orders, login credentials etc. The situation sometimes arises where we need to either extract information from the SalesForce CRM or add data to it.

SalesForce has an API (Application programming interface) setup which makes connecting to their system relatively easy. They have a website dedicated to developing on the SalesForce platform: http://developer.force.com

Since we use PHP this is the method we used to connect to SalesForce and the documentation can be found here: PHP Integration

SalesForce provide a Tool kit for PHP and this is what you should start with, it can be downloaded from here: Toolkit for PHP

Below is an example of how to connect to SalesForce and extract some customer information:

<code>// Include the class file of which ever account type you're using. Eg. Partner
require_once ('soapclient/SforcePartnerClient.php');

// Create a new connection and login to the account
$aMySforceConnection = new SforcePartnerClient();
$aMySoapClient = $aMySforceConnection->createConnection("soapclient/partner.wsdl.xml");

// This login function takes 2 parameters in this format: 'Email address',// 'PasswordSecurityToken' (The second one is the security token joined to the password)
// The security token can only be found by requesting a new one which is found here:
// SalesForce > Setup > My Personal Information > Reset My Security Token
$aMylogin = $aMySforceConnection->login("justin@bluelinemedia.co.uk", "passwordLErsT8SdWEEG9kdlWtHpmDLE");

// Select whatever information you need from the SalesForce database
$aQuery = "SELECT Id, FirstName, LastName, Department, OwnerId, Birthdate FROM Customer WHERE FirstName = 'Tim'";

// Some of the common objects that can be queried:
$aResponse = $aMySforceConnection->query($aQuery);

// QueryResult object is only for PARTNER client
$aQueryResult = new QueryResult($aResponse);

// You can work with the results just like a SQL result set.
// Remember that it's treated like an object!

foreach ($aQueryResult->records as $aRecord)
{
print_r($aRecord, true);
}</code>

The above code needs the 'soapclient folder' that is found in the PHP toolkit to work correctly.

Hopefully that will help you in learning how to make a simple connection to a SalesForce CRM.