Joseph U.
Joseph U.

Reputation: 4607

How do I access a particular element in a Force.com SOAP response?

I am having difficulty accessing a particular element nested in my SOAP object result. The Salesforce toolkit is returning the following when I run this code:

print_r ($response->records[0]->fields

RETURNS

stdClass Object (

[Number_of_Residents_c] => 1
[State
_c] => LA
[City__c] => New Orleans
[Placement_Incentive__c] => Yes
[Total_number_of_schools__c] => 125.0
[Total_Number_of_Students__c] => 24471.0
[Total_Number_of_Employees__c] => 1700.0
[Total_Operating_Revenue__c] => 1.2E8
[Governance_Model__c] => Mayoral/State Control
[CEO_Superintendent_Appointment_Year__c] => 2007
[Trained_Leader__c] =>
[Final_Press_Clip_1_Title__c] => Clip 1 Sample
[Final_Approved_Clip_1__c] => http://www.google.com
[Final_Press_Clip_2_Title__c] => Clip 2 Sample
[Final_Approved_Clip_2__c] => http://www.yahoo.com
[Final_Press_Clip_3_Title__c] => Clip 3 Sample
[Final_Approved_Clip_3__c] => http://www.bing.com
[Final_Press_Clip_4_Title__c] =>
[Final_Approved_Clip_4__c] =>
[Final_Press_Clip_5_Title__c] =>
[Final_Approved_Clip_5__c] =>
[News_Clip_Status__c] => Complete
[New_Organization__c] => Yes
[Student_Achievment_URL__c] => http://www.aol.com
[Work_Life__c] =>
[Placement_Incentive_Description__c] => $1000
[0] => SObject Object ( [type] => Account [fields] => stdClass Object ([Name] => Sample District Name) )
[2] => SObject Object ( [type] => Contact
[fields] => stdClass Object ( [Name] => Paul Smith ) ) )

If I want to get the value of Placement_Incentive_Description__c I can do so by using:

print_r ($response->records[0]->fields->Placement_Incentive_Description__c

However the difficult lies in how to access the name field in the Account object which seems to be a child of a field named [0]. I have tried several combinations but have had no luck.

Upvotes: 1

Views: 241

Answers (1)

Lylo
Lylo

Reputation: 1261

Wow thats weird try something like this.

$attr = 0;

$response->records[0]->fields->{$attr}

Upvotes: 2

Related Questions