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
Dharmin Kansara 8Dharmin Kansara 8 

How to run a flow every hour?

Hello, 

I am aware that we can run flows normally every day at a specific time, but how can we run it every hour, I need my certain Cases to be edited every hour. To be specific, when record is edited it will trigger a record-triggered flow which will do an action.

 

There is also an app --> https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000FZ981UAD&tab=r

But this is not working for me, I can see apex job running but my Cases are not updated.

 

Can you help, I am sure it is possible to do atleast with Apex Jobs

 

Best Answer chosen by Dharmin Kansara 8
Dharmin Kansara 8Dharmin Kansara 8
I am sure we could achieve this using Apex, but as an Admin also I was able to solve using simple method:
  • A helper checkbox field (Default = False)
  • A record triggered flow on Case where whenever it is created / edited
  • I set it to FALSE
  • Run a scheduled Path - After 1 hour, which sets it to TRUE
  • As soon as it is true, again the same flow runs (as it is edited) and next recur for after 1 hour will be scheduled and it will keep recurring.

Just some heads-up:

Maximum 2000 elements limit. According to this limit, in a flow transaction, the total number of flow elements that can be executed is 2000.
250,000 records limit. As per this limit, per 24 hours, the total number of records returned by all the scheduled flows’ Start element query must not be more than 250,000 records or the number of user licenses in your org multiplied by 200, records, whichever is greater.
 


Here is the official documentation for considerations on scheduled flow
https://help.salesforce.com/s/articleView?id=sf.flow_considerations_trigger_schedule.htm&language=en_US&type=5 (https://help.salesforce.com/s/articleView?id=sf.flow_considerations_trigger_schedule.htm&language=en_US&type=5)

All Answers

DishantDishant (Salesforce Developers) 

Hi Dharmin,


You can try the Apex Scheduler coding part. This method is more complex, but it allows you to schedule a single flow to run every hour.


To do this, you will need to create a custom Apex scheduler class. This class will need to implement the Schedulable interface.


Once you have created the scheduler class, you will need to schedule it to run every hour. You can do this using the System.schedule() method.


For more information on how to create a custom Apex scheduler, please refer to the Salesforce documentation:


Apex Scheduler

https://developer.salesforce.com/forums/?id=9062I000000DGxwQAG



However, this idea is already discussed on Ideas exchange on Salesforce as it is not directly available. Below is the link for the same. 

https://ideas.salesforce.com/s/idea/a0B8W00000GdhJkUAJ/hourly-scheduled-flows

Please mark this as a best answer if this helps you! 

Dharmin Kansara 8Dharmin Kansara 8

Hi Dishant,

Thanks for the reply.

 

I have created a class which runs the flow successfully but I get this error: "If you use a record variable to update or delete records, the ID value in the variable must be populated."

Something like this:

global class ScheduledFlow implements Schedulable {
   global void execute(SchedulableContext sc) {
       Map<String, Id> params = new Map<String, Id> ();
            Flow.Interview kycScoringFlow = Flow.Interview.createInterview('Scheduled_Flow',params );
            kycScoringFlow.start();
   }
}
 

Here is the anonymous code:

ScheduledFlow sc = new ScheduledFlow();
String cronExp = '0 25 * * * ?';
String JobId = system.schedule('Flow_Name', cronExp, sc);
 
 

Seems like Flow is not grabbing the recordId in between, do I need to pass it somewhere?

Dharmin Kansara 8Dharmin Kansara 8
Hi Harsh, I have actually followed that same post before and also job ran but with this error: ""If you use a record variable to update or delete records, the ID value in the variable must be populated."" Do you know about this? You can check below, the code from your post worked but if you look closely, flow cannot find "recordId" that is why it is null [image: Screenshot 2023-10-20 at 18.34.05.png]
Dharmin Kansara 8Dharmin Kansara 8
I am sure we could achieve this using Apex, but as an Admin also I was able to solve using simple method:
  • A helper checkbox field (Default = False)
  • A record triggered flow on Case where whenever it is created / edited
  • I set it to FALSE
  • Run a scheduled Path - After 1 hour, which sets it to TRUE
  • As soon as it is true, again the same flow runs (as it is edited) and next recur for after 1 hour will be scheduled and it will keep recurring.

Just some heads-up:

Maximum 2000 elements limit. According to this limit, in a flow transaction, the total number of flow elements that can be executed is 2000.
250,000 records limit. As per this limit, per 24 hours, the total number of records returned by all the scheduled flows’ Start element query must not be more than 250,000 records or the number of user licenses in your org multiplied by 200, records, whichever is greater.
 


Here is the official documentation for considerations on scheduled flow
https://help.salesforce.com/s/articleView?id=sf.flow_considerations_trigger_schedule.htm&language=en_US&type=5 (https://help.salesforce.com/s/articleView?id=sf.flow_considerations_trigger_schedule.htm&language=en_US&type=5)

This was selected as the best answer