0

Can I schedule a flow for any other frequency than daily / weekly?

How could I schedule a flow for every 6 months?

0

2 Answers 2

3

No, you can't directly do this. However, you can create a small Schedulable class:

public class FlowScheduler implements Schedulable {
    String flowName;
    Map<String, Object> parameters;
    public FlowScheduler(String flowName, Map<String, Object> parameters) {
        this.flowName = flowName;
        this.parameters = parameters;
    }
    public void execute(SchedulableContext context) {
        Flow.Interview interview = Flow.Interview.createInterview(flowName, parameters);
        interview.start();        
    }
}

And then schedule it:

System.schedule(
    'Flow every 6mos', // Unique Job name goes here
    '0 0 0 1 1/6 ?', // change 1/6 to whatever months you want
    new FlowScheduler('myFlowName', new Map<String, Object> {
        /* put your parameters here */
    })
);

This example runs on January and July first at midnight of the user that runs this code. This wrapper is flexible enough that you can use any supported scheduling type that Schedulable offers.

However, one caveat: you can only have 100 scheduled jobs at once, so this wouldn't be practical for a per-record basis. If you need something like that, just schedule a flow daily and have it query records from six months ago (probably via a custom date field) to keep the values up to date.

2

An alternative, non-Apex, solution is to schedule the flow every day and have a decision block as the first element to decide if the current date is your six month mark (e.g. 1/1/20xx or 7/1/20xx).

  • If yes, do your work
  • If not, the flow stops

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.