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
deafpandadeafpanda 

Getting custom fields using SOQL qith SOAP API - PHP

Hey there,

 

I'm having trouble accessing custom fields using the SOAP API with PHP.  Here's my query:

SELECT npo02__Formula_MailingAddress__c, npo02__HouseholdPhone__c, npo02__MailingCity__c, npo02__MailingCountry__c, npo02__MembershipJoinDate__c, npo02__MembershipEndDate__c FROM npo02__Household__c

 This query works fine on Force.com explorer.  Using SForceEnterpriseClient->query(), here is what the exact same query returns:

QueryResult Object
(
    [queryLocator] => 
    [done] => 1
    [records] => Array
        (
            [0] => SObject Object
                (
                    [type] => 
                    [fields] => 
                )

            [1] => SObject Object
                (
                    [type] => 
                    [fields] => 
                )

            [2] => SObject Object
                (
                    [type] => 
                    [fields] => 
                )

            [3] => SObject Object
                (
                    [type] => 
                    [fields] => 
                )
.....etc

 

Can someone explain what I'm doing wrong?  Non-custom fields are picked up fine, but I can't seem to access any custom fields through the API.

 

Thanks a lot!

Best Answer chosen by Admin (Salesforce Developers) 
deafpandadeafpanda

So, after a bit more Googling, I found a solution that works for me, and you were right about it being to do with my WSDL.  The old, standard WSDL without my custom fields was being cached, so updating it to my custom version wasn't doing anything.  Adding this line fixed this for me:

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

 Thanks for pointing me in the right direction!

All Answers

sfdcfoxsfdcfox

You need a custom Enterprise WSDL, assuming you're using the Toolkit. Use the Partner version, which is not subject to this little caveat, or generate a new Enterprise WSDL. The Enterprise WSDL can only "see" values for fields which are defined in the WSDL, as all other values will return as non-existant; it is said to be "strongly typed". The Partner WSDL, by contrast, is "loosely typed" and can determine any field or object without it being explicitly written into the WSDL. You can generate an Enterprise WSDL using Setup > Develop > API.

deafpandadeafpanda

Hey, thanks for your help.  I am actually using the Enterprise WSDL that I have generated, using Setup > Develop > API.  Checking through my WSDL, it does have references to my custom fields.  But I am still unable to retrieve these fields (I get no error and standard fields are retrieved normally).

 

Any ideas?

 

Thanks!

deafpandadeafpanda

So, after a bit more Googling, I found a solution that works for me, and you were right about it being to do with my WSDL.  The old, standard WSDL without my custom fields was being cached, so updating it to my custom version wasn't doing anything.  Adding this line fixed this for me:

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

 Thanks for pointing me in the right direction!

This was selected as the best answer
Neha1234Neha1234
Where did you add this line?