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
gagan batragagan batra 

I want to get all the items associated with an sales order using SOQL ,

 I tried with  this SELECT Id, Name, (SELECT  Name FROM Sales_Order__c ) FROM Sales_Order_Line_Item__c but not working
Raj VakatiRaj Vakati
try this  one this  

SELECT Id, Name,   Sales_Order__r.Name  FROM Sales_Order_Line_Item__c 
Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Gagan

The inner query is used for retrieving child records but you are trying to access the parent record.In order to access fields of parent you need to follow this approach : 
For querying parent fields : PARENT_OBJECT_FIELD_NAME__r.FIELD_NAME : Sales_Order__r.Name
For querying child records : Use inner query : (SELECT Id FROM CHILD_RELATIONSHIP_NAME__r)

Cheers!!! 
gagan batragagan batra
Thanks for the anwser,
Actully i need all sales order with its all line items  created today.
How can I achive this.
Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Gagan
The query would be : 
[SELECT Id, (SELECT Id FROM SALES_ORDER__r {the Child relation ship Name + '__r' } WHERE CREATEDDATE = TODAY) FROM Sales_Order__c  WHERE CREATEDDATE = TODAY]

Try to map the query with this : [select Id ,(Select Id from Contacts ) from Account] 
This would help you understand.

Cheers!!!