-2

Our case definition contains a billion custom fields, and I appear to be fine SELECTing FieldName__c in an API call. But I want to get a field, Case_Assignee__c which is defined as a reference. Using it always says there is no such field despite it being in the describe for Case.

The field would be a user, just like Owner is, but Case_Assignee__c.Name fails along with any other permutation I can think of. So I guess I'm missing some key Salesforce magic knowledge. Any pointers?

2
  • 3
    More information is needed here. Please edit your question to add details. Showing us the query that you're trying to run would be the bare minimum. You should also copy/paste the entirety of the error message that you're getting (trying to shorten/paraphrase errors means that you are leaving out important information). Educated guess is that you're using __c instead of __r when you are trying to reference data on a related object. I.e. you should be using My_Relationship_Field__r.Related_Field__c. Commented Jan 31, 2024 at 19:06
  • Pow! Case_Assignee__r.Name was the magic format @DerekF, thanks for the nudge in the right direction! Commented Jan 31, 2024 at 21:05

1 Answer 1

0

When trying to query for data on other, related records (usually on a different SObject but you can have a lookup relationship between records of the same SObject), you need to change the __c of the relationship field to __r.

E.g.

SELECT Id, Name, CreatedDate, Special_Owner__r.Name FROM Opportunity 

That's true for any custom relationship field.

For standard relationship fields, the API name is usually of the form <object name>Id. E.g. OpportunityId on OpportunityLineItem, OwnerId on nearly all SObjects, etc...

For those, you'd just drop the "Id" part.

SELECT Id, Name, Opportunity.Name, Opportunity.StageName FROM OpportunityLineItem 

Do note that this is specific to child -> parent queries, i.e. traversing upwards in the relationship hierarchy. Querying downwards in the hierarchy (parent -> children) also needs you to use __r, but there's a bit more to it and that doesn't seem to be relevant to this particular question.

More detailed/thorough information can be found in the Relationship Queries section of the SOQL/SOSL Reference.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.