Difference between __c and __r?

__r represents a custom relationship. There are two uses for __r. We use it when we query a custom relationship from child to parent, or from parent to child.

For example, if you have two custom objects, called Service__c and Service_Line__c, where the Service Line has a field that references a Service as its parent, you can query from child to parent, or parent to child.

The child to parent relationship query looks like this:

SELECT Id, Service__c, Service__r.Name FROM Service_Line__c

While the parent to child relationship looks like this:

SELECT Id, Name, (SELECT Id, Name FROM Service_Lines__r) FROM Service__c

To access parent and children records in Apex Code, you'd use the same syntax:

Service_Line__c line = [select ... from service_line__c where ...];
if(line.service__r.name == 'Master Service') {
    // Do something
}

Service__c service = [select ... from service__c where ...];
for(Service_Line__c line:service.Service_Lines__r) {
    // Do something
}

Each mechanism has a specific purpose depending on your intent.


__c is for Custom objects For example: Custom_Object__c . It is used for reference custom object in Apex or visualforce page, formula field etc internally. Used as suffix.

__r is for Custom objects reference For example: Custom_Object__r . It is used for reference custom object relation ship name in Apex or visualforce page, formula field etc. Used as suffix.

In image you have posted: Hiring_Mansger__r is relationship name.

Native object don't require __c as suffix.


I think the easiest way to think about this is that the relationship name might not be the same as the object name. For example, if you have a custom object Car_Market_User__c, you might have an object Car__c, with a Buyer__r and Seller__r. Typically, however, the name is the same, which is why it's auto generated based on the model name as Car_Market_User__r.