i am getting this error in lin 12, how to pass multiple product code using list, can anyone please help me out.
Error--Error: Compile Error: Invalid bind expression type of OpportunityLineItem for column of type String at line 12 column 92
public class Procuct_Adding_To_Order{
public static void productOrder(List<OpportunityLineItem> oli){
set<Id> setOppId = new set<Id>();
for(OpportunityLineItem obj: oli){
setOppId.add(obj.OpportunityId);
}
List<OpportunityLineItem> ProdCode = [Select ProductCode from OpportunityLineItem where id IN: oli];
List<Product2> Prod_Nam = [Select id,Product_Abb__c from Product2 where ProductCode IN: ProdCode];
List<opportunity> needed = [Select Master_Opportunity__c from opportunity Where Opportunity.id =: setOppId];
List<OrderItem> orderIt = new List<OrderItem>();
for(Order ord: [Select id from Order where opportunityId =: needed[0].Master_Opportunity__c])
{
for(OpportunityLineItem o : oli)
{
for(Product2 pr : Prod_Nam)
{
OrderItem op = new OrderItem();
op.Opportunity_del__c = needed[0].Master_Opportunity__c;
op.orderId = ord.id;
op.Order_Name__c = Pr.Product_Abb__c;
op.PriceBookEntryId = o.PriceBookEntryId;
op.Quantity = o.Quantity;
op.UnitPrice = 100;
orderIt.add(op);
}
}
}
upsert orderIt;
}
}
prodCode
is reallyoliList
;prod_nam
is reallyprodList
;needed
is something likeoliOppoList
; that said the first three soqls could be combined as you can fetch Product2 parent fields from the OLI and OLI can be queried foropportunityId
. Using maps instead of lists is so much more useful and can avoid the loops within loops