I am trying to find how to go about resolving this error.

Error: Compile Error: Illegal assignment from List to List at line 4 column 21

trigger productupdate on Opportunity (after insert,after update)
      List<Opportunity> opp=[select id,Production_date__c,(select id,ServiceDate from OpportunityLineItems)from Opportunity];
                for(Opportunity op:opp)
                    date olddate=oldMap.get(op.id).Production_date__c;
                    date newdate=newMap.get(op.Production_date__c);
                    integer diffdays=olddate.daysbetween(newdate);
                    for(OpportunityLineItem opl:op.OpportunityLineItem)
                        opl.ServiceDate =(op.diffdays+opl.ServiceDate);
                 update opp;

enter image description here

1 Answer 1


Looks like you might have a class in the system with the name opportunity.

Either rename that class to something or instead of Opportunity use System.Opportunity

  • 1
    thanks it worked, I had the apex class in the same name opportunity
    – arun
    Jul 25, 2021 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .