function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bdensmorebdensmore 

Can't display Custom Field Values

I'm trying to grab data from a custom field on my Contact object in PHP but for some reason it always comes back empty. In my query I can filter on that field and using the SOQL Explorer if I run the same query I see the value for that field. Is there something special I need to do to get the value of a special field?

This is my code, the ID field shows up fine but not the custom_field__c.

try {
  $mySforceConnection = new SforceEnterpriseClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
  $mylogin = $mySforceConnection->login("mylogin", "mypassword");

  $query = "Select Id,custom_field__c From Contact where custom_field__c != null";
  $options = new QueryOptions(10);
  $mySforceConnection->setQueryOptions($options);
  $response = $mySforceConnection->query($query);
  !$done = false;
  $RecordNum = 0;

  echo "Size of records:  ".$response ->size."<br />";

  if ($response->size > 0) {
    while (!$done) {
      foreach ($response->records as $record) {
          $RecordNum = $RecordNum + 1;
        echo $RecordNum.". ".$record->Id." - ";
        echo $record->custom_field__c."<br />";
      }
      if ($response->done != true) {
        try {
          $response = $mySforceConnection->queryMore($response->queryLocator);
        } catch (Exception $e) {
          print_r($mySforceConnection->getLastRequest());
          echo $e->faultstring;
        }
      } else {
        $done = true;
      }
    }
  }

} catch (Exception $e) {
  print_r($mySforceConnection->getLastRequest());
  echo $e->faultstring;
}
JimAJimA
Hi there,
 
try this in your for each record loop
 
  $sObject = new SObject($record);
  echo $sObject->fields->custom_field__c;
openbookopenbook
Hi

I'm having the same issue using the PHP Toolkit.  I've created a custom field in the lead object, but when I try to query a record and display a custom field I can't see the custom field in the results: ( im simply using a SOQL query )

Code:
$query_result = $sf->client->query("SELECT id, custom_field__c FROM Lead");
print_r($query_result);


This query shows the all lead objects but where the leads have custom_field data entered it wont show.  The strange things is that the field displays ok when I run the query in the SOQL Query Browser im using (http://www.pocketsoap.com/osx/soqlx/).  I've tried regenerating my wsdl file as well but that hasnt helped.

Anyone got any tips?
SuperfellSuperfell
the PHP tools tend to overly cache your WSDL, there's some php.ini flag you can get to get it to behave in a more expected manner. (i can't remember it right now, but its been covered on this forum a bunch of times)
openbookopenbook
Hi

thanks for your reply, the cache turned out to be the problem yes, I solved it by switching the toolkit to use a file named without the .xml extension thus invalidating the cache.

Cheers
Andy