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
ch3fch3f 

Custom Field Queries PHP vs Eclipse = Different result

I am just starting out developing to this API.  I have php code that is not returning the same result and the IDE query when a custom field is in the statment.

 

 

<?php define("SOAP_CLIENT_BASEDIR", "soapclient"); require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php'); require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php'); require_once (SOAP_CLIENT_BASEDIR.'/function.php'); require_once ('userAuth.php'); try { $mySforceConnection = new SforceEnterpriseClient(); $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl'); $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD); $query = "Select Name, CID__c, BillingCity, Account_Executive__c From Account a limit 20"; $something = "SELECT OwnerId Owner.Alias FROM Lead limit 1"; $createResponse = $mySforceConnection->query($query); echo "<table border=1 cellpadding=2>"; echo "<tr>"; echo "<th> Name </th>"; echo "<th> CID </th>"; echo "<th> City </th>"; echo "<th> Account Executive </th>"; echo "</tr>"; foreach ($createResponse as $createResult){ //print_r($createResult); //print("<br>"); for ($i=0, $num_result=count($createResult); $i < $num_result; $i++){ echo "<tr>"; echo "<td>"; print($createResult[$i]-> Name); echo "</td>"; echo "<td>"; print($creatResult[$i]-> CID__c ); echo "</td>"; echo "<td>"; print($createResult[$i]-> BillingCity ); echo "</td>"; echo "<td>"; print( $createResult[$i]-> Account_Executive__c ); echo "</td>"; echo "</tr"; } } echo "<table border=\"1\">"; } catch (Exception $e) { echo $mySforceConnection->getLastRequest(); echo "</br>"; echo "<h1>faultstring:</h1> </br>"; echo $e->faultstring; echo "</br>"; return $return; } ?>

 

The Custom fields come out blank.  However when I run the same SOQL query in Eclipse I get the records for the custom fields.  Am I doing this correctly?  I have read about cached data could this be my problem?

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Park Walker (TAGL)Park Walker (TAGL)

The cached 'data' would be the WSDL. You don't mention if you obtained the enterprise WSDL for the organization after adding the 'CID' field, but you would need to do that to get the query to work. You need to update the WSDL file (and delete the one from the cache) after any change to the definition of the objects you are working with.

 

It might also be helpful to know what that print_r() statement produces when you uncomment it.

All Answers

ZCJZCJ

Thought I'd bump this post, as I'm having the same issue of querying through PHP

Park Walker (TAGL)Park Walker (TAGL)

The cached 'data' would be the WSDL. You don't mention if you obtained the enterprise WSDL for the organization after adding the 'CID' field, but you would need to do that to get the query to work. You need to update the WSDL file (and delete the one from the cache) after any change to the definition of the objects you are working with.

 

It might also be helpful to know what that print_r() statement produces when you uncomment it.

This was selected as the best answer
msimondsmsimonds

I would also add this to the top of any script that you write using PHP:

 

 

 

ini_set("soap.wsdl_cache_enabled", "0"); 

 

 

That way it will not cache your WSDL at all

 

~Mike

ch3fch3f

Sorry for leaving this open after I figured out the problem....This ended up not being a cache issue.  What it ended up being is an out of date WSDL file that i was using.  Once I updated the file I started getting the data returned.

James W.ax741James W.ax741

The SOAP caching issue was the major drama for me.

 

I kept finding the same solution (update your WSDL) which I did and was still encountering the same issue. I really think this particular setting should be HIGHLIGHTED somewhere in the PHP section of the site in relation to the using the API. Also, information about publishing the most up-to-date version of the WSDL affecting the ability to SELECT custom fields should also be highlighted.

 

This is my first Salesforce integration and I was ready to kill it!

 

Thanks all that responded to this forum and many like it.