You need to sign in to do that
Don't have an account?
jdeveloper
what the difference between __c and __r
hi, im new to salesforce and i was wondering what was the difference between __c and __r when refering to a custom object. Also can u give me examples. thanks
Hi,
"__r" is used for retrieving field values from the object's related another object when those objects have relationship via Lookup field.
See links below for detail and samples.
In Formula:
http://developer.force.com/cookbook/recipe/displaying-fields-from-a-related-record-on-a-detail-page
In SOQL:
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm
All Answers
Hi,
"__r" is used for retrieving field values from the object's related another object when those objects have relationship via Lookup field.
See links below for detail and samples.
In Formula:
http://developer.force.com/cookbook/recipe/displaying-fields-from-a-related-record-on-a-detail-page
In SOQL:
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm
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
}
"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"
I think it's unlocking my understanding of custom relationship :)
__c and __r are not use inSOQL with standard object..
It is use only with custom object???
While working on similar thing I had a slightly different observation I have 1 child table with a look up field and a Parent table
I have a query that fetches fields from the child table and I wanted to retrive a few parent columns using the same SOQL using the "__r." notation
My Child table name is : Tour_Expense_Submission__c
My Parent table name is : Tour_Budget_Pre_Approval__c
Look up field name in child table is : Against_Tour_Budget_Pre_Approval_ID__c
So I tried to to use the SOQL as :( which did not work)
select id,name,Against_Tour_Budget_Pre_Approval_ID__c,Tour_Budget_Pre_Approval__r.name from Tour_Expense_Submission__c where id='a0FDO000000CnGC2A0'
And the one that worked was
select id,name,Against_Tour_Budget_Pre_Approval_ID__c,Against_Tour_Budget_Pre_Approval_ID__r.name from Tour_Expense_Submission__c where id='a0FDO000000CnGC2A0'
Can you tell me why it worked like this ?