Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have Three Objects A, B and C. C is junction Object

Through the Object of C , I want to access the fields of A and B.

I am doing it as


Am I doing something wrong here?

share|improve this question

You should read through this Relationship Queries documentation that amongst other things explains the use of __r references.

If you have these custom objects:


the field reference would be:

C__c c = ...;
Object aField = c.A__r.Field__c;

Note that for standard objects e.g. Contact the reference fields don't follow this pattern but rather are usually just the same as the referenced object type (with the ID of the referenced object usually having an ID suffix).

share|improve this answer

If C is your junction object then C has a reference to an A and a reference to a B

So in SOQL you could write something like

thingC__c anExampleC = [select my_thing_A__r.thing_A_field__c, my_thing_B__r.thing_B_field__c
                        from thingC__c
                        where id = '.....'];
share|improve this answer
so does that mean that I can refer any field in a by A.B.field_of_B__c – user2703132 Jul 23 '14 at 15:55
The junction object provides a many to many relationship. So any particular A could be related to zero, one or lots of B records. There will be one C record per junction between A and B. – Doug B Jul 23 '14 at 16:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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