+ Start a Discussion
RICITRICIT 

Custom Fields

Hello. I am trying to access Salesforce throught the PHP API, and I am unable to retrieve any data from custom fields. I am using the enterprise wsdl, and a modified version of a code example I found online: [php code:]

function get_accounts($connection, $table, $id, $rows, $column)
{
  $query = "SELECT ";
  foreach($rows as $row)
  $query.=$row;
  $query.=" FROM ".$table." WHERE(".$column."='".$id."')";
  $queryOptions = new QueryOptions(10);
  $response = $connection->query($query, $queryOptions);
    // New code starts here
    if ($response->size == 1)
    {
        $accounts = $response->records;
    }
else if($response->size != 0)
{
  $accounts = $response->records;
           // Cycles through additional responses if the number of records
            // exceeds the batch size
        while (!$response->done)
        {
            set_time_limit(900);
            $response = $connection->queryMore($

response->queryLocator);
            $accounts = array_merge($accounts, $response->records);
 
        }
    }
 
  return $accounts;
} [end php code]
 
Then my syntax for extracting the data is: (since it should only get one record with the id) $accounts[0]->fieldname; or, if it is a custom field: $accounts->fieldname__c;.
Can someone please enlighten me?
jblockjblock

I'm having the exact same problem. Here's what I've got:

 

I've added 3 "custom" fields to the standard "Case" object. When I request their values over the api (using the __c names), no values are returned.

 

The REALLY wacky thing is that when I attempt to access those same fields through the Windows program called "Apex Explorer 8.0", I get the values back. I'm using the SAME login in the Apex Explorer as I am with the PHP code.

 

Can someone please help!

Thank you,

Jon

jblockjblock

One other clue to my problem: I *am able* to create() new Case records with values in my custom fields. The problem is that I am unable to retrieve those values.

 

I dug deep into the PHP class and inspected the lines that actually call the query() method to retrieve data and I see that an array of php standard objects come back and they are missing my custom fields, even though the query string requests them. :(

 

Any ideas?

Jon

tom_gtom_g
I was having the same problem.  I just needed to generate an updated enterprise.wsdl.xml file (Setup > Develop > API > Generate Enterprise WSDL) and everything works as expected now.
RICITRICIT
That was the first thing I tried. It seems my problem is a little deeper than that.
rdave18rdave18

I have the same problem.

 

  1. PHP v5.2 / toolkit 13_0 
  2. AppExplorer 8 reads data correctly
  3. I can set the custom field
  4. Select on the custom field does not return the field in the result set; other 'standard' fields are returned.
  5. I have run the code against a developer account and that retrieves custom fields
  6. I am using the same ID for AppEx and code when accessing the production instance.

 

So, code retrieves custom field on dev instance while but not in production.

 

Any ideas?

 

rdave18rdave18

I solved this problem. 

 

  1. The enterprise.wsdl from my dev instance was being cached in /tmp. 
  2. The field name is different for the custom field between dev and production instances.
  3. So, switching to production would use the cached wsdl which did not have the correct field name.

I used:

 

ini_set('soap.wsdl_cache_ttl', '15');
ini_set('soap.wsdl_cache_dir', './wsdl-cache');

 

...which overrides php.ini SOAP cache setting and my 'local' cached WSDL expiry to 15 seconds.

 

HTH.