0

here i am trying to fetch opportunity lookup id from opportunityLineItems bt getting this error.-

Error: Compile Error: expecting a colon, found 'oli.OpportunityId' at line 6 column 80

can anyone please help me

public Class Procuct_Adding_To_Order
{

   public static void productOrder(List<OpportunityLineItem> oli){

    List<Order> ord = [Select id from Order where opportunityId IN: oli.OpportunityId];

    for(OpportunityLineItem o : oli)
    {
      OrderItem op = new OrderItem();
      op.OpportunityId = oli.OpportunityId;
      op.ListPrice = oli.ListPrice;
      op.orderId = ord.id;
      op.Product2Id = oli.Product2Id;
      op.ProductCode = oli.ProductCode;
      op.Quantity = oli.Quantity;
      op.TotalPrice = oli.TotalPrice;
      ord.add(op);      
    }
       insert ord;
   }
}
0

In your query you need to add colon after IN

you may need to use like

public static void productOrder(List<OpportunityLineItem> oli){
    set<Id> setOppId = new set<Id>();
    for(OpportunityLineItem obj: oli){
        setOppId.add(obj.OpportunityId);
    }
    List<Order> ord = [Select id,EffectiveDate from Order where opportunityId IN: setOppId ];

   }

Updates change oli to o. oli is a list and o is a single record so you can just write list.fieldName. You need to write record.FieldName.

Same for ord

public static void productOrder(List<OpportunityLineItem> oli){ 
    set<Id> setOppId = new set<Id>(); 
    for(OpportunityLineItem obj: oli){ 
        setOppId.add(obj.OpportunityId); 
    } 
    map<Id, Id> mapOpportunityIdToOrderId = new map<Id, Id> ();
    for(Order ord: [Select id, opportunityId from Order where opportunityId IN: setOppId])
    {
        mapOpportunityIdToOrderId.put(ord.opportunityId, ord.Id);
    }
    List<OrderItem> orderIt = new List<OrderItem>(); 
    for(OpportunityLineItem o : oli) 
    { 
        OrderItem op = new OrderItem(); 
        op.OpportunityId = o.OpportunityId; 
        op.ListPrice = o.ListPrice;
        if(mapOpportunityIdToOrderId.containsKey(o.opportunityId))
            op.orderId = mapOpportunityIdToOrderId.get(o.opportunityId);
        op.Product2Id = o.Product2Id; 
        op.ProductCode = o.ProductCode; 
        op.Quantity = o.Quantity; 
        op.TotalPrice = o.TotalPrice; 
        orderIt.add(op); 
    } 
    insert orderIt; 
} 
10
  • now getting this error--- Error: Compile Error: Initial term of field expression must be a concrete SObject: List<OpportunityLineItem> at line 6 column 82 – RAT__ Feb 5 '16 at 7:26
  • @RAVIGAUTAM check my updated ans – Ratan Paul Feb 5 '16 at 7:35
  • dude again now it's giving the same error -- Error: Compile Error: Initial term of field expression must be a concrete SObject: List<OpportunityLineItem> at line 6 column 69 Please check my updated code – RAT__ Feb 5 '16 at 7:48
  • Please check my updated code – RAT__ Feb 5 '16 at 7:48
  • @RAVIGAUTAM inside for loop don't use oli instead use only o. oli is a list and o is a single record so you can just write list.fieldName. You need to write record.FieldName. – Ratan Paul Feb 5 '16 at 7:51
1

You'll need to create a map to establish a link between the order and the product depending on the opportunity common between them.

then cycle through a loop to assign only the id of the order in question to the respective opportunity

if you want a common order try using LIMIT 1 in the query and return the value to an order variable.

Feel free to chat for further queries :)

Regards A.S.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.