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
Marquette77Marquette77 

Trigger to update stage 30 days after Opportunity.Created Date

Hello -

 

I'm trying to expire Opportunities (by updating the Stage value) 30 days after the creation of said Opportunity.  I can do so with a Workflow Rule, but this will only fire the Field Update when the Opportunity record is edited.  As a result, if the Opportunity record isn't accessed during the timeframe when the 30 day window passes, the expiration will not occur.  The obvious way to handle this is a trigger, but I'm not sure if this is correct; I also could use some assistance with the syntax of the trigger (I have very limited experience with Apex coding).

 

I think this is a very simple procedure and could use some assistance/recommendations.

 

Thanks.

 

Tim J.

Marquette77Marquette77

Here's the trigger code I've come up with so far, and the resulting compile error:

 

trigger BudgetaryExpiry30Days on Opportunity (before update) {
//update Stage to ClosedBudgetary 30 days after Creation Date
FOR(Integer i=0; i<1000; i++){
IF (ISPICKVAL(Opportunity.Opp_Priority__c, 'Budgetary')
&& (TODAY() - DATEVALUE(Opportunity.CreatedDate)  >  30))
Opportunity.StageName = 'Closed Budgetary';
}
}

 

Error: Compile Error: Expression cannot be assigned at line -1 column -1

 

Any help?

 

Thanks.

 

 

yatsevsky_devyatsevsky_dev
Hi, you're trying to use formula constructs where Apex code is expected, they're not the same.
Marquette77Marquette77

yatsevsky_dev-

 

Can you provide a quick example of the difference between Apex and formula constructs, or a reference site where I can quickly learn for myself?  I am not familiar with Apex at all.

 

Thanks for the feedback - hope you can help.