function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vinayakamurthyvinayakamurthy 

regarding __r

i want to know about __r type of relationship in that which is master and which is child,and how to query and insert data...

souvik9086souvik9086

There are two types of Relationship Queries

 

Parent to Child

 

SELECT Id,Name,(SELECT ID,Name FROM Childs__r) FROM Parent__c;

 

When you want your child objects datas along with your parent you use the above query where ChildObjects__r is used.

 

Child to Parent

 

SELECT ID,Name, Parent__r.Name FROM Child__c;

 

When you want any parent object data from a child query then you can use like this ParentObject__r.FieldName.

 

Hope this will help.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

asish1989asish1989

Suppose there are two object one is Account which is master and another object is Order__c which is a child.

Order__c has lookup field "Account__c" to Account .

 

First way

 

You want to fatch orders of Particular account.

List<Order__c> listOfOrders = [Select Id, Name ,Account__c From Order__c Where Account__r.Name = :'testAccount'];

That means If you want to acess parent record being at child object then you need to use lookup field with appending __r.

here Account__r is used.

 

Second way


If YOu want to query parent Account with chiled records then...

 

 List<Account> listOfAccounts = [Select Id, name,(Select Id, name From Order__r) From Accounts];

Here account with their order is fatched.

 

Suppose you want to update some field of Account of paerticular order, you can do by using this Account__r.

 

Satish_SFDCSatish_SFDC
Further details:

http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_relationships.htm

Regards,
Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.