0

I have 2 custom objects. Let's name it to object 1 and object 2. Both of these objects have their own field.

Object 1 have fields: Customer name, item, quantity, total, .....

object 2 have fields: Customer name, credit limit balance, .....

Both objects have customer name field, where both of them are lookup fields (to account object-standard object).

So now I want to display item, quantity, total, from object 1 to object 2 based on customer name, but I don't know how to query it. Anyone can help me?

Select Customername__c, item__c, quantity__c, total__c,
                             (Select Customername__c, creditlimitbalance__c From Object2__r) 
                             from Object1__c

I got this error:

Didn't understand relationship 'From Object2__r' in FROM part of query call.

I think because object 1 and object 2 don't have any relation. But they have field lookup to the same object (account with customer name)

I really appreciate it if you guys can help me. Do let me know if need more information. Thank you

1 Answer 1

2

When you include a subquery in a SOQL, you need to use relationshipName. So lets say you have a BoatReview__c.object object and it has a lookup to Boat__c.object.

And your relationship name in BoatReview__c.object is <relationshipName>Boat_Reviews</relationshipName>

Then your query will become:

SELECT Id, (SELECT Id FROM Boat_Reviews__r) FROM Boat__c

If you are not using proper relationship or have misspelled the name , then you will get this error. Didn't understand relationship 'From Object2__r' in FROM part of query call.

If you are querying on totally unrelated objects then you need to use two separate queries.

And I believe you want to fetch data for Object1 and Object2 where both have same account.

In that case you can query

SELECT Id, (SELECT Id FROM Object1s__r), (SELECT Id FROM Object2s__r) FROM Account

This will fetch all accounts and fetch Object1s__r data and Object2s__r data in list if its there in database.

2
  • select id, (select id from Sales__r) from account I do like this, but still, get the same error, INVALID_TYPE: select id, (select id from Sales__r) from account ^ ERROR at Row:1:Column:28 Didn't understand relationship 'Sales__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. Jul 6, 2021 at 2:03
  • Sokay I got it. Thank you for your help :-) Jul 6, 2021 at 7:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .