You need to sign in to do that
Don't have an account?
Deepak Pansari
How do i get Product Name for an Opportunity?
Hi,
i want to get all the product name related with an Opportuntiy.
i want to write one trigger for that.
Does any body know the SQL (how do i query to salesforce) or any Idea.
Regards,
Deepak
public static void GetLineItems(List<Opporunity> opps) { Set<Id> oppIds = new Set<Id>(); for(Opporunity a : opps) { if(a.HasOpportunityLineItem) oppIds.add(a.Id); } Map<Id, List<OpportunityLineItem>> lineItems = new Map<Id, List<OpportunityLineItem> ([Select o.PricebookEntry.Name, o.PricebookEntryId, o.OpportunityId From OpportunityLineItem o Where o.OpportunityId In :oppIds]); for(Opporunity a : opps) { for(OpportunityLineItem b : Map.get(a.Id) { System.debug(b.PricebookEntry.Name); } } }
Try this might work?
All Answers
public static void GetLineItems(List<Opporunity> opps) { Set<Id> oppIds = new Set<Id>(); for(Opporunity a : opps) { if(a.HasOpportunityLineItem) oppIds.add(a.Id); } Map<Id, List<OpportunityLineItem>> lineItems = new Map<Id, List<OpportunityLineItem> ([Select o.PricebookEntry.Name, o.PricebookEntryId, o.OpportunityId From OpportunityLineItem o Where o.OpportunityId In :oppIds]); for(Opporunity a : opps) { for(OpportunityLineItem b : Map.get(a.Id) { System.debug(b.PricebookEntry.Name); } } }
Try this might work?
Can you post code or actualerror message which you are getting?
Map<Id, List<OpportunityLineItem>> lineItems = new Map<Id, List<OpportunityLineItem> ([Select o.PricebookEntry.Name, o.PricebookEntryId, o.OpportunityId From OpportunityLineItem o Where o.OpportunityId In :oppIds]);
This is the error I'm getting (In Eclipse) -
Save error: Invalid nested collection type
There is no error code associated with it.
Thanks!
i think the error is in the map syntax try this
Map<Id, List<OpportunityLineItem>> lineItems = new Map<Id, List<OpportunityLineItem>>([Select o.PricebookEntry.Name, o.PricebookEntryId, o.OpportunityId From OpportunityLineItem o Where o.OpportunityId In :oppIds]);
You will get another error about the invalid initial type. The problem is the mapping of the list in this sql statement though