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
SoCal AdminSoCal Admin 

Referencing SObject field data

Hi everyone.

 

I'm new to Salesforce Toolkit 20.  Looking for info on accessing Custom fields in custom objects.

 

Query works fine in Force.com explorer and in PHP script, but output is not showing field names.  I've updated the enterprise.wdsl.xml file and clearly see the Correct custom field info in the xml file, but query looks like this:

 

$query = "Select Id, NameInfo__c, data__c from customobject"

 

and output looks like this:

 

SObject Object

(  

 [type] =>    

 [fields] =>    

  [Id] => a1eE0000000LABcIAO

)

 

SObject Object

(

[type] =>    

[fields] =>    

[Id] => a1eE0000000LABdIAO

)

 

SObject Object

(    

[type] =>    

[fields] =>    

[Id] => a1eE0000000LABeIAO

)

 

The ID can be printed with $record->ID.  How do I reference the custom fields?  Any attempt ends with "Undefined property: SObject::$NameInfo or   ...NameInfo__c     

 

Any suggestions or recommendations for where to look next?

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

It seems like you may be mixing the Enterprise access method with the Partner access method. While you may choose to use either, the code to access fields is different. Your code is appropriate for the Partner access method where the fields are returned in the field object (e.g. Account->fields->Name). If you are using your enterprise WSDL this will not work as the field are returned as fields on the object (e.g. Account->Id, Account->Name, etc). Trying to use an enterprise WSDL with partner code will likely produce the results you are seeing, although I have never tried it.

 

The first step is to decide which access method you are going to use and then get the appropriate sample code working, ignoring custom objects and fields. Then try it with your custom objects and fields. If you still cannot access custom fields check to be sure that the permissions are set to allow the user you are loggin in as access to those fields. Make sure you delete the WSDL file from the cache (or turn off WSDL caching) each time you update your WSDL file. 

 

Park

All Answers

Park Walker (TAGL)Park Walker (TAGL)

It seems like you may be mixing the Enterprise access method with the Partner access method. While you may choose to use either, the code to access fields is different. Your code is appropriate for the Partner access method where the fields are returned in the field object (e.g. Account->fields->Name). If you are using your enterprise WSDL this will not work as the field are returned as fields on the object (e.g. Account->Id, Account->Name, etc). Trying to use an enterprise WSDL with partner code will likely produce the results you are seeing, although I have never tried it.

 

The first step is to decide which access method you are going to use and then get the appropriate sample code working, ignoring custom objects and fields. Then try it with your custom objects and fields. If you still cannot access custom fields check to be sure that the permissions are set to allow the user you are loggin in as access to those fields. Make sure you delete the WSDL file from the cache (or turn off WSDL caching) each time you update your WSDL file. 

 

Park

This was selected as the best answer
SoCal AdminSoCal Admin

 

Yes - I tried many different variations simply because the sample code wasn't working.  I am specificially accessing the enterprise.wsdl.xml file.

 

The sample code works perfectly fine as long you only access the ID field.  Accessing any other field fails with "Undefined Property" - even the Name  field, which I thought was considered standard. (not custom).

 

I've already verified the SELECT statement using Force.com explorer.  I know the fields are correct.  I only used the "partner" access method to dump the entire object in an attempt to figure out the structure of the object.

 

I also rebooted the server to make sure the cache was cleared.

 

Here are two separate examples:

 

Code:

foreach ($response->records as $record) {

    //print_r($record);   // used to dump record contents

    print $record->Id;   // This always works

    print $record->Name;     // non-custom, always fails

    //print $record->Id . $record->InvoiceDate;     //Custom Field, Display Name, always fails

    //print $record->Id . $record->InvoiceDate__c;     //Custom Field, API Name, always fails

}

 

3 Separate attempts:

 

Error referencing $record->Name 

a1eE0000000LABaIAOPHP Notice:  Undefined property: SObject::$Name in /var/www/html/soapclient/test.php on line 19

 

Error referencing $record->InvoiceDate

PHP Notice:  Undefined property: SObject::$InvoiceDate in /var/www/html/soapclient/test.php on line 21 a1eE0000000LABeIAO

 

Error referencing $record->InvoiceDate__c 

PHP Notice:  Undefined property: SObject::$InvoiceDate__c in /var/www/html/soapclient/test.php on line 21 a1eE0000000LABeIAO

SoCal AdminSoCal Admin

Ok it was a cached WSDL.xml file, determined by disabling the cache.

 

The strange thing - this is a crazy cache.  How is it useful?  If I have to manually disable a cache, is it really working?

 

I updated the enterprise WSDL file yesterday and rebooted the server today and the code still failed.  Then i added the PHP code to disable the cache and the code worked..?!?

 

When does the cache ever update itself?    Not that I care too much.  I'll just keep it disabled for now...

 

Thanks for your help.

shivdhanshivdhan

HI 

I have a phpsoap server and a wsdl file. With the help of php client i am able yo call service and it is giving out put in Std class.

but when i call this service with jsp client then it give some if like@354663dg . how can i get actual output with jsp client and APEX code