57. Is there any Difference between __c and __r in salesforce

396    Asked by ChristianParsons in Salesforce , Asked on Aug 28, 2023

 I was trying to read an article and understand the difference between __c and __r in Salesforce, but I could not. Can anyone please help me understand this?

Answered by Darsh K

__r represents a custom relationship, which is used to query about a custom relationship from child to parent or from parent to child. On the other hand, __c is for Custom objects, which refers to custom objects in Apex or Visualforce page, formula field, etc., internally.

Another point to remember is that the relationship name and the object name might not be the same.

Let’s take an example- suppose you have a Class__c parent object (one) with a child relationship to Student__c objects (many). If you want to get the name of the student and the class associated with each student, then you can use __r relationship to get to Class__c when querying Student__c.



Your Answer

Interviews

Parent Categories