0

I have a requirement where I need to trigger a workflow without user interaction.

I created a workflow that sends an E-Mail notification to the Opportunity Owner if Opportunity.CloseDate equals TODAY, which is working fine as long as the record is edited manually and closeDate is manually set to today's date.

My problem now is, that when I set the closeDate to somewhere in the future, two weeks for example, the workflow will not be triggered, because nobody edited the record.

How can I archieve a solution for this?

I found a quiet simillar question here, but this seems to be old and not following best practice. Is there a solution without apex?

2
  • 3
    Have you looked at setting a time triggered workflow which sents email after close date or simply a Scheduled triggered flow which runs daily at a set time. The second option would work for existing records as well while the first would require a data update.
    – manjit5190
    Commented Jun 16, 2021 at 14:31
  • 1
    why not use a record-triggered flow with scheduled paths - where the path executes at 0 days from Opportunity.CloseDate? As the close date changes, SFDC 'reschedules" the path to the new closedate
    – cropredy
    Commented Jun 16, 2021 at 21:50

1 Answer 1

1

The easiest solution is to create Apex Class that implements Schedulable and make query there SELECT Id FROM Opportunity WHERE CloseDate = TODAY and just update the records.

However, I recommend you to move from workflow to another Apex Class (handler) and make all necessary actions in it, because nothing will be updated in opportunity records along the way.

After creation of the Scheduler, schedule it to run every day at specific time through Setup -> Apex Classes -> Schedule Apex.

Draft implementation for better understanding:

public without sharing class RunWorkflowScheduler implements Schedulable {
    public void execute(System.SchedulableContext sc) {
        List<Opportunity> opps = [SELECT Id FROM Opportunity WHERE CloseDate = TODAY];
        
        //for workflow
        update opps;
        
        //if you move workflow into code
        /*write your email notifications sending here
        * do not update opportunity records*/
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .