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
MARCO SELLERIMARCO SELLERI 

Trigger to update status opportunity field based on opportunity created date

Hi all,

I've a question, maybe it's simple, but I'm pretty new on this..

I need to update the opportunities status, once the current date is 7 days older than the opportunity created date and the same status is "open"..

example:
an opportunity has been created the 10th of May 2017 (and it's status is "open"), but after 7 days, if the status is still open, I need to set it to "closed".
In my case the opportunity is a custom object.

Can you help me with that? I've tried but I'm not able to find the correct solution.

Thanks
Kaj E. PetersenKaj E. Petersen
Hi Marco,

I don't believe you need a trigger, you just need a time-based workflow.   A trigger will only work if someone updates the record and I don't think that is happening since the status has not changed.  

Quick Find -> Workflow Rules
New Rule
Select your object
Give the Rule a name and change the Evaluation Criteria to Created. 
Rule Criteria: Status = Open
Save and Next. 
Time-Dependent Workflow Actions
7 Days After Your Object: Created Date
Add New Field Update: 
Update status to Closed.  

Then activate, and you should be good to go.  It doesn't help with current records, you will need to have a different solution for those existing records.  

Hope this helps,

Kaj