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
Vijaya Kumar RegantiVijaya Kumar Reganti 

How to query on "Opportunity_Product" Object ?????

Hi Friends,

 

I have a requirement to query on the standard object "Opportunity_Product".I don't know the object name to query.

 

Please help me.

 

Thanks,

 

Vijay

Best Answer chosen by Admin (Salesforce Developers) 
Satish_SFDCSatish_SFDC
OpportunityLineItem

Regards,
Satish Kumar

All Answers

Satish_SFDCSatish_SFDC
OpportunityLineItem

Regards,
Satish Kumar
This was selected as the best answer
Siddhant IndraSiddhant Indra

parentOpportunitySet = Opportunity Id Set

 

List<OpportunityLineItem> opportunityLineItemList = [Select o.PricebookEntryId, o.OpportunityId, o.Id From

OpportunityLineItem o where o.OpportunityId = :parentOpportunitySet];

for(OpportunityLineItem opp : opportunityLineItemList){
pricebookEntryIdSet.add(opp.PricebookEntryId);
}

List<PricebookEntry> pricebookEntryList = [Select p.Product2Id, p.Name, p.Id From PricebookEntry p where Id= :pricebookEntryIdSet];

for(PricebookEntry p : pricebookEntryList){
productIdSet.add(p.Product2Id);
}

List<Product2> product2List =[Select p.Name, p.Id From Product2 p where Id = :productIdSet];

for(Product2 p2 : product2List){
opportunityProductNameList.add(p2.Name);
}

 opportunityProductNameList will have all Product Names associated with Opportunity.

 

Product2 objetc is the Opportunity_Product object.

This will help you..

 

David Roberts 4David Roberts 4
You can also use the Force.com Developer Console and directly type a query into the Query Editor such as:
select name,opportunity.name from opportunitylineitem where name like 'widget%'