You need to sign in to do that
Don't have an account?
randombard
Join Lists to produce a new one
Hi All,
So here is what I am trying to do..
I want to create a list of all opportunity line items that are in next years price book keep the salesprice from the previose year and add them to a new opportunity.
creating the opp shouldnt be a problem but I am having trouble getting my head arround bilding the list of products to add to the new opp, I have as follows.
trigger RenewOp on Opportunity (before update) { for(opportunity o: trigger.new){ IF(o.iswon==true && o.Renew_With_what_year_pricebook__c !=null){ String opptyId = o.Id; String PBName = o.Renew_With_what_year_pricebook__c + ' ' + o.PricebookName__c.abbreviate(0,5); List<OpportunityLineItem> OLI = [Select UnitPrice, Quantity, ServiceDate, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_Asset__c From OpportunityLineItem where OpportunityId = :opptyId]; List <PricebookEntry> PBE =[Select ID, Product2Id, PricebookEntry.Pricebook2.Name FROM PricebookEntry Where PricebookEntry.Pricebook2.Name =:PBName and Product2Id in :OLI.PricebookEntry.Product2Id]; } } }
but get the following error:
Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<OpportunityLineItem> at line 11 column 66
Any pointers greatfully apreciate.
R
My Bad,I did not see the IN operator,try below code :-
List <PricebookEntry> PBE =[Select ID, Product2Id, PricebookEntry.Pricebook2.Name
FROM PricebookEntry
Where PricebookEntry.Pricebook2.Name =:PBName and Product2Id = :OLI[0].PricebookEntry.Product2Id];
All Answers
Change your code from
List <PricebookEntry> PBE =[Select ID, Product2Id, PricebookEntry.Pricebook2.Name
FROM PricebookEntry
Where PricebookEntry.Pricebook2.Name =:PBName and Product2Id in :OLI.PricebookEntry.Product2Id];
to
List <PricebookEntry> PBE =[Select ID, Product2Id, PricebookEntry.Pricebook2.Name
FROM PricebookEntry
Where PricebookEntry.Pricebook2.Name =:PBName and Product2Id in :OLI[0].PricebookEntry.Product2Id];
Hi Vinit_Kumar,
I now get
Error: Compile Error: IN operator must be used with an iterable expression at line 11 column 73
Thanks
R
My Bad,I did not see the IN operator,try below code :-
List <PricebookEntry> PBE =[Select ID, Product2Id, PricebookEntry.Pricebook2.Name
FROM PricebookEntry
Where PricebookEntry.Pricebook2.Name =:PBName and Product2Id = :OLI[0].PricebookEntry.Product2Id];