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
Lukesh KarmoreLukesh Karmore 

i have to write soql query on product2 any one know it

i have to write soql query on product2 , means need to fetch products releted to OpportunitylineItem .
 list<OpportunityLineitem> oliList=[SELECT id,Quantity,Product2.Name,Product2.Total_Quantity__c,Product2.Available_Quantity__c FROM OpportunityLineitem 
I know  above way to query product. want to know below query that return same
 list<Product> ProductList=[SELECT id,name, Available_Quantity__c FROM Product where -------------
hope u understand my question any one know the answer
Thank you
PriyaPriya (Salesforce Developers) 
Hi Lukesh,

Can you please elaborate the requirement and let me know what you need here?

Regards,
Priya Ranjan
Suraj Tripathi 47Suraj Tripathi 47
HI Lukesh,
The easiest way to fetch your data is the one you already stated.
Now the second query you are trying is you are trying to fetch the data from the Product2 object and the WHERE clause is used to check the condition. You cannot query the data because there is no direct relation between product2 and OpportunitylineItem.

Please mark it as the best answer if this helped you.
Thank You
Regards 
Suraj Tripathi
Lukesh KarmoreLukesh Karmore
Thank you for your replies
 OpportunityLineItem is not directly releted to Product2
so how to query product releted to OpportunityLineItem
i need to  query on product object.
ANUTEJANUTEJ (Salesforce Developers) 
Hi Lukesh,

>> https://salesforce.stackexchange.com/questions/155222/fecthing-records-from-unrelated-objects-but-commonly-have-parent-object

>> https://trailblazers.salesforce.com/answers?id=9063A000000lDKXQA2

The above link shows way to write soql to fetch records from unrelated objects.

Let me know if it helps you and close your query by marking it as the best answer so that it can help others in the future.  

Thanks.