Salesforce integration using nusaop

Error message

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.

Currently we are carrying out a piece of integration work between Drupal and Salesforce. Drupal is responsible for pulling the data from Salesforce and this achieved by calling the SOQL api via a webservice. The data is returned in a SOAP format. This article assumes you are using this salesforce client

SOQL stands for sforce object query language and is the mechanism for retrieving data from salesforce's database. SOQL has a number of interesting limitations when compared with a standard query language such as SQL. It doesn't support complex queries meaning that table joins can not be performed, the maximum length of any query is 10000 characters and the number of records returned in a single query is limited to at most 2000 records. The actual number of records returned depends on nature of the fields being returned. This is done to ensure that SOAP messages don’t become large.

We need to create a new Salesforce object and pass in location of partner.wsdl.xml (the WSDL file we are using) and then log onto the system:

$file = $filelocation.‘partner.wsdl.xml'

$conn = new salesforce($file);
$loginResult = $conn->login($username, $password);

SOQL queries are similar in structure to SQL:

$soql = 'SELECT c.Id, c.Career_Interest__c FROM Contact c WHERE Id = '$sfId'";

A query is trigger in the following maner:

$result = $conn->query($soql);

Once the data has been returned the data needs to be manipulated to make it easier to process. The first test is to see whether we have in fact retrieved any records. The records returned can be found here:

$records = $ result ['result']['records'];

Once we have determined if records are present the way we treat the data that has been returned depends on whether we expect a single row or multiple rows to be returned.

In case of a single returned value we always want to make sure that we only process the first record:

$records = $records [0]->values;

The values returned by the query can then be easily accessed as we have an array to process:

$id = $records[‘Id’];

If we expect multiple records to be returned we iterate through the returned object and process all the items. Returned values are accessed via the values attribute of the returned object:

foreach ($records as $record) {
$id = $record->values[‘Id’];

Given the limit that salesforce places on the number of records that can be returned it certain cases it maybe necessary to perform multiple queries to obtain every record. Whether a query has finish can be determined by using the following logic

if (isset($result['result']['done']) && $ result['result']['done'] == 'false' && isset($result['result']['queryLocator'])) {
$result = $conn->queryMore($r['result']['queryLocator']);

So getting data from salesforce isn't hard you just need to understand the nature of the data you are retrieving.