I have seen quite a few posts on this here at Stackexchange, followed them as mentioned, for some reason it is not working for me. I am trying to retrieve records from the custom Object[Segment] which has a lookup relationship with the Account Standard object.

Here how the field is setup in the Account object - enter image description here

Here how the Segment custom Object is setup - enter image description here

I still have no idea why the below soql statements dont work.

select Id,Name,Segments__r.Id from Account
select Id,Name,(select Id from Segments__r) from Account

For both the above queries this is the error message I get -

Didn't understand relationship 'Segments__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

1 Answer 1


This doesn't work:

select Id,Name,Segments__r.Id from Account

because the relationship name is incorrect. As shown in your screenshot, the relationship field API name is Segment_ID__c.

Note also that you shouldn't traverse a relationship just to get the Id. The relationship field itself stores the id, Segment_ID__c.

This doesn't work:

select Id,Name,(select Id from Segments__r) from Account

because in the schema shown, the Segment object is the parent of Account. This is a parent-child subquery to obtain records that are children of Account, with the relationship name Segments__r.

I'd strongly recommend reading through the entire Relationship Queries section of the SOQL and SOSL Reference. It covers all of these variations of relationship queries thoroughly.

If your intent is that Segment should be a child of Account, your schema is built incorrectly: in that case, the relationship field should be on Segment, pointing to Account.

  • Thanks David Reed, I will have to go through the article on relationships.
    – sumchans
    Feb 6, 2021 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .