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
Naitik RaiNaitik Rai 

i want to update priority on activity(overdue)

I'm total new to Apex (specially in coding) and trying to figure out, to update the Priority to be High on an activity
after it has become overdue by 10 days.

The Priority field update is the only thing that I need to set and I cannot figure out what I'm doing wrong.  
My error is both on line 3; unexpected token ':' and unexpected syntax: 'mismatched input':' expecting Semicolon.

User-added image
Any help would be greatly appreciated!
Best Answer chosen by Naitik Rai
Suraj TripathiSuraj Tripathi
Hi Naitik,

Try This Piece of code,

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

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

Then Please use this variable declaration in your if statement like:
t.ActivityDate = dt && t.Status != 'Completed'
 
trigger ActivityPriorityStatus90DayUpdate on Task (before update) {

     for(Tasks t : Trigger.new) {

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

		  }
     }
}


& Please mark this answer as best answer if this solves your issue.

All Answers

Suraj TripathiSuraj Tripathi
Hi Naitik,

Try This Piece of code,

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

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

Then Please use this variable declaration in your if statement like:
t.ActivityDate = dt && t.Status != 'Completed'
 
trigger ActivityPriorityStatus90DayUpdate on Task (before update) {

     for(Tasks t : Trigger.new) {

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

		  }
     }
}


& Please mark this answer as best answer if this solves your issue.
This was selected as the best answer
Naitik RaiNaitik Rai
Thank you Suraj. This works!