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;
}
}
Best Answer
In your first SOQL, thou you are only querying for product codes, you will get back opportunity line item in the list.
So, in your second SOQL you are passing OpportunityLineItem list instead of product codes.
to fix this, after your first query, iterate and store the product codes into a separate collection / array and use it in your second SOQL.
something like