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
ryandevitoryandevito 

Accessing Custom Objects via PHP SOQL call

Using the SOQL commander I am able to query and retrieve values from fields within custom objects without issue. 

 

When I try to use the same exact query from PHP I get "Notice: Undefined property: SObject::$Date_Requested__c in /var/www/........"

 

..... where date_requested__c is one of the custom fields I'm trying to pull.

 

How come I cannot retrieve values from the API like I can using the SOQL commander SQL dashboard? 

 

 

Is querying custom fields from the API not allowed?

 

Thanks in advance,

Ryan

 

Best Answer chosen by Admin (Salesforce Developers) 
ryandevitoryandevito

I figured out that the problem was I was logged in using my developer force account, instead of my regular salesforce account.  Thus, the wsdl files were different.  Once I turned off the wsdl caching in php and re-downloaded the appropriate wsdl file, it worked fine.

 

Thanks!

All Answers

ptepperptepper

Hi Ryan,

 

This sounds like a problem with your WSDL file. 

 

You can probably solve it by either 

 

(a) using the partner WSDL file or

 

(b) regenerating a new enterprise WSDL file

 

partner is loosely typed, so it should be ok with queries containing all objects and fields, but enterprise is strongly typed, so it requires you regenerate it anytime you add new objects or fields. 

 

Check out the docs: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_partner.htm

 

best

-paul

ryandevitoryandevito

Hi Paul

 

Thanks for the prompt response.  I refreshed the enterprise WSDL, however this did not solve the problem.  I expected this, because the objects are not new, but rather have been around for months now.  

 

It seems very odd since I'm using the exact same query that I ran in the SOQL commander, just in my PHP code.  My code is below for reference:

 

$query = "

SELECT

   Date_Resource_Requested__c,

   Network_or_Advertiser_Id__c,

   Contract_Type__c,

   Contract_Date__c,

   Client_Name__c,

   Client_email_address__c

FROM

   SFDC_Request__c

WHERE

   Id='{$request_id}'";

 

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

 

print_r($response);

 

 

When I print_r the $response object, (aside from the object not defined error messages) I see the following:

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

        )

    [size] => 1
)

Notice: Undefined property: SObject::$Date_Resource_Requested__c in ... on line 42 Notice: Undefined property: SObject::$Network_or_Advertiser_Id__c in ... on line 43 Notice: Undefined property: SObject::$Contract_Type__c in ... on line 44 Notice: Undefined property: SObject::$Contract_Date__c in ... on line 45 Notice: Undefined property: SObject::$Client_Name__c in ... on line 46 Notice: Undefined property: SObject::$Client_email_address__c in ... on line 47 

ryandevitoryandevito

I figured out that the problem was I was logged in using my developer force account, instead of my regular salesforce account.  Thus, the wsdl files were different.  Once I turned off the wsdl caching in php and re-downloaded the appropriate wsdl file, it worked fine.

 

Thanks!

This was selected as the best answer
Mark RoachMark Roach
I'm facing same problem of getting empty Custom Object as:

QueryResult Object
02(
03    [queryLocator] =>
04    [done] => 1
05    [records] => Array
06        (
07            [0] => SObject Object
08                (
09                    [type] =>
10                    [fields] =>
11                )
12 
13        )
14 
15    [size] => 1
16)

Does anyone have a solution?