5

So With the following trigger I wrote, I get an error on the line that says Trigger.oldMap( t1.Id ).IsClosed: The error is

"Variable does not exist: Trigger"

Which seems very odd to me, can anyone see what I'm doing wrong?

trigger TaskStatusChanged on Task ( after update ) {

    // For all the tasks that have been updated
    for( Task t1 : Trigger.new ) {

        // If this task has been closed or opened
        if( t1.IsClosed != Trigger.oldMap( t1.Id ).IsClosed ) {

            // If the task has been closed
            if( t1.IsClosed ) {
                 // Stuff
            }     

            // If there aren't any other open tasks, then update the Case object.
            if( !otherOpenTasks ) {
                //Stuff
            }


       }

       // If the task has been opened
       else if( !t1.IsClosed ) {
           // Stuff
       }

       // If the Task doesn't have an IsClosed value
       else {
           // do nothing
       }
    }
  }      
}
9

The syntax is not correct. You have no Get call.

Change

Trigger.oldMap(t1.Id).IsClosed

to

Trigger.oldMap.get(t1.Id).IsClosed
9

It should be Trigger.oldMap.get(t1.Id).IsClosed. Because you left out the function get, Apex Code's scope resolution first tried to find a function called oldMap on the class Trigger, which doesn't exist, so it then tried to find a variable called Trigger, which also doesn't exist.

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.