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
JimAJimA 

Access field Contact.FirstName from Case query

Hi All,
 
If I'm running the following query:
 
SELECT Id, AccountId, Contact.FirstName FROM Case
 
How do I access the Contact.FirstName value with the PHP toolkit? I tried $sObject->fields->FirstName but it doesnt work.
 
Thanks for the help!
 
Alex 2.0Alex 2.0
Jim

can't remember at the moment, but var_dump is your friend ;)

try

var_dump($sObject);

--Alex

RyanBiesRyanBies
I'm a noob at SOQL, but your Query seems to be malformed, at least by SQL standards, because you're requesting Contact.FirstName without including Contact from the tables you're selecting. In SQL, your query would look more like this:

SELECT Case.ID, Case.AccountId, Case.ContactId, Contact.FirstName
FROM Case, Contact
WHERE Case.ContactId = Contact.Id

The WHERE clause would be required here, because you're requesting information that's stored in multiple objects, and the server needs to know how to join them.

Again, that's paraphrased, but hopefully it'll get you going in the right direction.

-R
SuperfellSuperfell
As Rick likes to say SOQL ain't SQL. The original query is fine, unfortunately i don't know the right PHP syntax to access the nested object.
RyanBiesRyanBies
oy. apologies for the misdirection. I'm taclking the same problem at the moment, so I'll let you know as soon as I get a solid result.

-R
RyanBiesRyanBies
It appears to be burried a bit.

I was able to access the FirstName information by:

$sObject->sobjects[0]->fields->FirstName

but the fact that sobjects is an array worries me. Im getting NULL answers for some Cases and have not yet checked to see if the array ever has more than one item. It appears as though Case/Contact ratio is not always 1:1, so you may want to run a foreach loop on $sObject->sobjects.