0

I want to get the opportunity line item from opportunity and using query like below

Select Id, (Select Id, name From OpportunityLineItems) 
   From Opportunity 
   where id in 
     (SELECT Sales_Order__r.SO_Lookup_to_Opportunity__r.Id 
        from Shipment__c where id='a043i00000ALiByAAL')

and getting this error

The inner select field 'Sales_Order__r.SO_Lookup_to_Opportunity__r.Id' 
    cannot have more than one level of relationships

Do we have to use two queries to get the required output means first query to get the opportunity id ,store it in a variable and then second one to get the opportunity line items from the retrived opportunity ID

2
  • 3
    Note that SO_Lookup_to_Opportunity__r.Id and SO_Lookup_to_Opportunity__c are semantically the same value, the former adds a relationship level... You should use __c rather than __r.Id when possible (which is usually always).
    – sfdcfox
    Commented Jul 2, 2021 at 15:58
  • @sfdcfox Thank you.
    – klnavi
    Commented Jul 5, 2021 at 3:06

0

You must log in to answer this question.

Browse other questions tagged .