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
arosysarosys 

SOQL Query (left join)

I have a custom object "SiteCart__c

It has Master-Detail Relationship field "SiteProduct__c"

which is related to another custom object "SiteProduct__c"

 

"SiteCart__c" has two fields "Quantity__c" and related field "SiteProduct__c"

 

I want to retrieve fields of SiteCart__c such that it will show Quantity and name,description,price etc of related product filed.

 

I am using following query :

 

SELECT Quantity__c,(Select Name,Description__c,Price__c,Image__c From SiteProduct__r) FROM SiteCart__c

 

But this showing error

"Didn't understand relationship 'SiteProduct__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names."

 

Please help me.

 

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9

Ahhhh....

Correct me if I am wrong.

 

SiteCart is the child right ? which contains the master detail ?

And you want to access the fields of the parent object ? Site product ?

 

You can directly access the fields of the parent like this[The earlier query was for accesing child records from parent]

 

SELECT Quantity__c,SiteProduct__r.Name,SiteProduct__r.Description__c,SiteProduct__r.Price__c,SiteProduct__r.Image__c  FROM SiteCart__c

All Answers

Avidev9Avidev9

Same old question!

The Master-Detail field will have a "Child Relationship Name" in the field detail. We generally add "__r" to this field name while doing relationship query.

 

The child relationship name generally is plural. So it should be something like "SiteProducts__r"

 

SELECT Quantity__c,(Select Name,Description__c,Price__c,Image__c From SiteProducts__r) FROM SiteCart__c

 

arosysarosys

I tried with SiteProducts_r also but didnt worked either.

 

"Didn't understand relationship 'SiteProducts__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names."

souvik9086souvik9086

Check the Custom Relationship name of this field SiteProduct__c. It must have some different name not this 'SiteProducts__r'.

Check in the object field definition.

 

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

Thanks

 

Avidev9Avidev9

I just guessed the name!

You actually should be doing what I instrcuted to 

 

The Master-Detail field will have a "Child Relationship Name" in the field detail. We generally add "__r" to this field name while doing relationship query.

arosysarosys

"Child Relationship Name" is "SiteProducts"

 

Although It was not that before i changed it to  "SiteProducts"

 

And is still giving error.

Avidev9Avidev9

Ahhhh....

Correct me if I am wrong.

 

SiteCart is the child right ? which contains the master detail ?

And you want to access the fields of the parent object ? Site product ?

 

You can directly access the fields of the parent like this[The earlier query was for accesing child records from parent]

 

SELECT Quantity__c,SiteProduct__r.Name,SiteProduct__r.Description__c,SiteProduct__r.Price__c,SiteProduct__r.Image__c  FROM SiteCart__c
This was selected as the best answer
arosysarosys

Thanks it worked.