More Dynamic Way to Schedule a Salesforce Flow with Invocable Schedule Flow

Image 00 How this solution works
  1. Run a flow / subflow with Invocable Method (or Apex Action in Flow), which means you can create a job to run your flow from other flows
  2. You can pass a String / Text variable to the flow you want to run. You have more than 1 variable? you can use a json and do the parsing inside the flow you want to trigger, here’s more info for that.
  3. With cron expression, you can define exactly WHEN (even exact second) and your own frequency to run the flow
  4. You can set whether you want to run your flow in future method or not, if you set it in future method, that means you’ll be able to do callouts before you commit DML transaction in your flow (bye bye Pause Element). As a setback, the flow you want to run may delay a little from the time you specified
  5. Not wanting to trigger the flow from other Flow? don’t worry you create a job to execute your flow from Anonymous Apex Window

Attributes

  1. Label : Cron Expression
    API Name : cronExpression
    Type : String (Mandatory)
    Description : An expression used to represent the time and date the job (or Flow) is scheduled to run. More info and samples about how to formulate cron expression: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
    Example : 0 0 10 ? * MON-FRI (Runs Monday through Friday at 10 AM)
  2. Label : Flow API Name
    API Name : flowApiName
    Type : String (Mandatory)
    Description : Flow API Name that you want to run with the scheduler
    Example : TestDummy_ScheduledFlow
  3. Label : Schedule Job Name
    API Name : scheduleJobName
    Type : String (Mandatory)
    Description : Unique name of the job you want to run, this will be important for you to monitor the status of your flow job
    Example : TestDummy_ScheduledFlow_10AM_MONtoFRI
  4. Label : Flow Namespace
    API Name : flowNamespace
    Type : String (Optional)
    Description : The namespace of your flow, if any
    Example : cool_package
  5. Label : Flow Parameter / Variable Name
    API Name : flowParameterName
    Type : String (Optional)
    Description : The variable name that available for input in the flow you want to run, if any
    Example : recordId / Input_JSON
  6. Label : Flow Parameter / Variable Value
    API Name : flowParameterValue
    Type : String (Optional)
    Description : If flowParameterName does not null, this will be the value of variable that available for input you set on flowParameterName
    Example : 0015g00000CKozcAAD / {“recordId” : “0015g00000CKozcAAD”, “isScheduled” : True}
  7. Label : Run Flow in Future Method, default to False if null
    API Name : runInFuture
    Type : Boolean (Optional)
    Description : if null will be automatically set to false. This attribute decides whether you want to run the flow in future method or not. If true, you will be able to do callout before DML transaction in the flow. As a setback, your schedule will be delayed a little, depends on the workload of your org. More info about future method : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_invoking_future_methods.htm
    Example : False
Image 01 Where to Find your Flow API Name
  1. Label : Job ID
    API Name : jobId
    Type : String
    Description : The job ID that generated for your flow to run
    Example : 08e5g00000MYuQE
Image 02 Sample Screen to Formulate a Flow Job
Image 03 Sample Screen to formulate a Flow Job
Image 04 Sample Screen to invoke the InvocableScheduleFlow based on Screen on previous screen
Image 05 Debug screen to formulate Flow Job
Image 06 Debug execution of InvocableScheduleFlow
Image 07 Debug Screen after InvocableScheduleFlow
Image 08 Go to Developer Console -> Debug -> and click Open Execute Anonymous Window
Image 09 Put the script, set your attributes into the Anonymous Window, and check the Open Log checklist
List<InvocableScheduleFlow.Request> requests = new List<InvocableScheduleFlow.Request>();
InvocableScheduleFlow.Request req = new InvocableScheduleFlow.Request();
req.flowApiName = 'Dummy_ScheduledFlow'; //mandatory
req.cronExpression = '0 45 22 ? * FRI-MON'; //mandatory
req.scheduleJobName = 'TestDummy_ScheduledFlow'; //mandatory
req.flowNamespace = null; //optional
req.flowParameterName = 'parameter'; //optional
req.flowParameterValue = 'This is a value'; //optional
req.runInFuture = false; //will set to false if null or not set
requests.add(req);
List<InvocableScheduleFlow.Result> results = InvocableScheduleFlow.invoke(requests);
System.debug(results[0].jobId); //the job id result
Image 10 Click execute, checklist Debug Only, and you’ll have the Job ID that created to run your flow job
Image 11 Result of the flow Job I created (see the email timestamp)
Image 12 Go to Setup and search for Scheduled Jobs
Image 13 You’ll see the list of Scheduled Jobs and when it will be run. Notice that the Job Name we set on the parameter will appear there
Image 14 Go to setup and search for Apex Jobs
Image 15 You’ll see the current status of the job you created with ScheduledFlow in the Apex Class field
Image 16 Click Del at the job you wanted to abort

--

--

--

A dots connector. open for part time, Email: munawirrahman@gmail.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Dangers of Over-Compartmentalizing Code

In defense of Open Source Software

How I built a CI server Using Docker

Ruby On Rails, The Good, the Bad, and the…Beautiful

Path to SaaS Updates/Upgrades

Agile Tools: The Burn-Up Chart

My Cisco Ideathon Internship Experience

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Munawirrahman

Munawirrahman

A dots connector. open for part time, Email: munawirrahman@gmail.com

More from Medium

Salesforce : Hierarchy Custom Settings

page for creating new custom setting of type hierarchy

Salesforce - The “Company” drama…

Salesforce: How I’d Handle Apex Classes

Salesforce + Highspot Integration