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
Stephanie AkinStephanie Akin 

Help with trigger

Hi. A friend helped me develop a trigger for when an activity with the subject File Forms from Recruit in EE Folder is changed to the status of completed it updates the opportunity stage to Day 1 Complete. 

But I am getting an error and I can't figure out why. Error: Compile Error: Variable does not exist: trigger at line 4 column 18

Any help is appreciated. 

Here is the code:

trigger updateStatus on Task (after insert, after update){
    List<Id> oppy_ids = new List<Id>();
    List<Opportunity> update_oppys = new List<Opportunity>();
    for(Task t : trigger.new()){
        //when subject is this, the opp should be start 10 day cycle
        if(t.Subject == 'File Forms from Recruit in EE Folder' && t.Status == 'Completed' && t.WhatId != null && String.valueOf(t.WhatId).startsWith('006')){
            oppy_ids.add(t.WhatId);
        }
    }

    for(Opportunity o : [SELECT StageName FROM Opportunity WHERE ID IN :oppy_ids]){
        // or whatever you need the stage  name to be
        o.StageName = 'Day 1 Complete';
        //add the opportunity to a list for dml
        update_oppys.add(o);
    }

    if(!update_oppys.isEmpty()){
        update update_oppys;
    }
}
Best Answer chosen by Stephanie Akin
Prabu MahalingamPrabu Mahalingam
Hey,
Simple fix just replace trigger.new() with trigger.new.  ie remove the round brackets ().

cheers!!