Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Salesforce by (11.9k points)

I have a custom date field for accounts in SalesForce: LastCheckedDate (API Name: LastCheckedDate__c)

I'm trying to use the SalesForce Enterprise API to query accounts based on that field. It returns results, and I can use the custom field in the WHERE part of the query, but I can't get it to actually show me the value of the custom field in the results.

This PHP code should get me the ID, name, and LastCheckedDate of any account that has been checked in 2011:

$query = "SELECT Id,Name,LastCheckedDate__c FROM Account WHERE LastCheckedDate__c > 2011-01-01";

$response = $salesforceConnection->query($query);

foreach ($response->records as $record) {               

    print_r($record);

}

It correctly only returns accounts that have been checked in 2011, but the result doesn't include the value of that custom field:

stdClass Object

(

    [Id] => 0015000000abcdefgh

    [Name] => Bob's Widget Factory

How can I get it to include the LastCheckedDate in the results objects?

1 Answer

0 votes
by (32.1k points)
edited by

I believe, the problem related to how you were parsing the data that was being returned. Instead of feeding the returned data into an SObject, you should now just accessing it directly as shown below:

try {

  $mySforceConnection = new SforcePartnerClient();

  $mySoapClient       = $mySforceConnection->createConnection(API_PATH . '/soapclient/partner.wsdl');

  $mylogin            = $mySforceConnection->login(API_USER, API_PASS . API_SECURITY_TOKEN);

  $query = 'SELECT C.Id, C.Full_Name__c

            FROM Contact__c C'; 

  $result = $mySforceConnection->query($query);

  for($i = 0; $i < count($result->records); $i++) {

    print_r($result->records[$i]->fields->Full_Name__c); 

  }

} catch(Exception $e) {

  print_r($e);

}

Become a salesforce certified administrator by going for Intellipaat’s Salesforce course! 

Related questions

Browse Categories

...