0

I would like to write a SOQL query which goes from Account > Contact > User(s)

Something like this:

[SELECT PersonContactId, PersonContact.Users, PersonEmail FROM Account WHERE ...]

But I get this error:

No such column 'Users' on entity 'Contact'.

I also get this error:

No such column 'PersonContact' on entity 'Account'

But the Account object has a field called PersonContactId with a relationship name PersonContact

enter image description here

And the Contact object has a child relationship named: Users

enter image description here

So therefore, I should be able to do PersonContact.Users

Questions

  1. What am I doing wrong?
  2. How can I get the User collection when querying Account
2

Child relationships are only accessible by a subQuery, which means

SELECT 
  LastName, 
  (
    SELECT Id
    FROM Users
  )
FROM Contact
WHERE ...

This kind of subQueries can only happen on the top-most level of your query, hence you won't be able to get to that level from Account. Try reworking your query from Contact instead, something like

SELECT 
  LastName, 
  (
    SELECT Id
    FROM Users
  )
FROM Contact 
WHERE Id IN (
  SELECT PersonContactId 
  FROM Account 
  WHERE...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.