function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tanya ShahTanya Shah 

Error in trigger

Whenever Opportunity Stage is Updated to “Closed Won” , need to update them on the OpportunityIineItem using trigger . Have created a custom field to update the systemdate.

It is giving me error "Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<OpportunityLineItem> at line 17 column 9 " . Where am i makeing mistake ?

 
​trigger OpportunityWon on Opportunity (after update) {

  Set<Id> relevantIds = new Set<Id>();
    // select relevant opportunities
    for(Opportunity o : trigger.new)
    {
        if(o.StageName == 'Closed Won' || trigger.oldMap.get(o.Id).StageName == 'Closed Won')
        {
            relevantIds.add(o.Id);
        }
    }

    // Line Items
   OpportunityLineItem[] olis = [SELECT ID, WonWhen__c, OpportunityId FROM OpportunityLineItem WHERE OpportunityId IN :relevantIds];
   for(OpportunityLineItem oli :olis )
   {
        olis.WonWhen__c = system.today();
   }

  if (olis.size()>0)
    update olis.values();

}

 
Jerome LusinchiJerome Lusinchi
Hi,

Line 17, replace "olis" by "oli"

Jerome 
Tanya ShahTanya Shah
Its giving me diff error now . Any thing wrong that i'm doing here ?
Jerome LusinchiJerome Lusinchi
what is the new error ?