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
Staci GregoryStaci Gregory 

Trigger a Priority update on overdue activities

I'm VERY new to Apex (literally all coding) and am trying to figure out how to update the Priority to High on an activity after it has become overdue by 10 days.

The Priority field update is the only thing that I need to happen and I cannot figure out what I'm missing.  My alerts are both on line 3; unexpected token ':' and unexpected syntax: 'mismatched input':' expecting Semicolon.
User-added image

Being pointed in the right direction would be greatly appreciated!
Best Answer chosen by Staci Gregory
Shawn Reichner 29Shawn Reichner 29
Looks like you never gave your for loop a variable declaration. 

Try This code....Please mark as best anser if this solves your issue. 

You may have to declare a date variable to set the -90 days for activity date such as:

Date Today = system.Today();
Date d1 = Today.addDays(-90);

Then use this variable declaration in your if statement like: t.ActivityDate = d1 && t.Status != 'Completed'

Shawn
trigger ActivityPriorityStatus90DayUpdate on Task (before update) {

     for(Tasks t : Trigger.new) {

              if(t.ActivityDate == system.today().addDays(-90) && t.Status != 'Completed')
              {
                        t.Priority = 'High';

              }

     }
}

 

All Answers

Shawn Reichner 29Shawn Reichner 29
Looks like you never gave your for loop a variable declaration. 

Try This code....Please mark as best anser if this solves your issue. 

You may have to declare a date variable to set the -90 days for activity date such as:

Date Today = system.Today();
Date d1 = Today.addDays(-90);

Then use this variable declaration in your if statement like: t.ActivityDate = d1 && t.Status != 'Completed'

Shawn
trigger ActivityPriorityStatus90DayUpdate on Task (before update) {

     for(Tasks t : Trigger.new) {

              if(t.ActivityDate == system.today().addDays(-90) && t.Status != 'Completed')
              {
                        t.Priority = 'High';

              }

     }
}

 
This was selected as the best answer
Staci GregoryStaci Gregory
Thank you!