Skip to main content Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.
Where do we use the __r suffix for the obj, is it used only for custom object only and child objects only
3 answers
  1. Apr 11, 2014, 8:33 AM
    So __r is used to access fields on the Related Parent Object(related either via Lookup Relationship or a Master-Detail Relationship) is SOQL Queries, in Visualforce Bound Variables etc.

     

    Now, you have to understand the fact that __r is only used in case of Custom Relationship Fields that are made on either the Standard or Custom Object.

     

    For example, if we consider the Contact and Account, the Contact has Relationship Field that looks up to the Account. So to access the fields on the related Account, we could write:

     

    SOQL Queries:

    SELECT Id, Account.Name, Account.BillingStreet FROM Contact

    Formula Fields:

    Account.Name, Account.BillingStreet

    Visualforce Tags:

    <apex:ouputField value="{!Contact.Account.Name}" />

     

    Now, let us take the example of the Opportunity object. This does not have any Lookup Field or Master-Detail Field to the Contact object. Now, say that I created one with the API Name – Contact__c. Now see how the usage differs when compared to the Standard (out-of-the-box Relationship fields):

     

    SOQL Queries:

    SELECT Id, Contact__r.Name, Contact__r.Mobile FROM Opportunity

    Formula Fields:

    Contact__r.Name, Contact__r.Mobile

    Visualforce Tags:

    <apex:ouputField value="{!Opportunity.Contact__r.Name}" />

  2. Apr 11, 2014, 8:08 AM
    it is used in relationship query

     

    ex: if contact is lookup in Acount

     

    if you want to get the contact firstname,lastname means you can use this

     

    select contact__c,contact__r.firstname from Account
0/9000