A Quick Guide To Scheduled Processing in Salesforce

scheduled processing

Two great ways to increase the adoption of your Salesforce solution are push notifications and automating recurring tasks. The Salesforce platform provides multiple ways to trigger scheduled functionality and bring the information to the user. This can be achieved in multiple ways in Salesforce. In this post, we will see different ways in which we can schedule the processing of information at a future date/time.

Scheduled Reports/Dashboards

The simplest form of receiving processed information in future is through scheduled reports or dashboards.

  • Scheduled Reports: In Lightning, you can subscribe to reports and configure them to run the reports at regular intervals. You can subscribe yourself and other users, groups, or roles to receive refreshed report results by email on a schedule that you set. The report can be scheduled to run daily, weekly or monthly (on one or more days in a month). The report results can be sent as an email with an attachment in XLSX or CSV format. You can also specify the “Run As” user for the report so that the report is generated with all the appropriate data as per the access of the running user. Another interesting feature is to specify a report condition so that recipients are notified when a total in your Salesforce report reaches a meaningful threshold. This allows you to highlight significant changes in reported data to the recipients.
  • Scheduled Dashboards: Similar to Salesforce reports, you can also subscribe yourself and other users, groups, or roles to receive refreshed dashboard results by email on a schedule that you set. You can also choose to just refresh the dashboard without sending the results by email so that the users viewing the dashboard see the latest data. Recipients see the same report data as the person running the report.

Scheduled Path in a Record-Triggered Flow

Salesforce Flow is a declarative process automation tool. In a record-triggered flow, apart from other activities, you can add a scheduled path which will run on a specified scheduled date/time. One can base the scheduled date/time on when the record is created or updated or on a date field value in the record. Scheduled paths run in the system context, so they have permission to access and modify all data. You can also specify a batch size to do any intensive batch records processing as part of the scheduled path. E.g. If you need to update all the accounts of a particular type when their parent account is updated. 

The scheduled paths can be used to make any updates on related records or perform any time-delayed action. Also, if you need to make any updates to one of the Setup objects, such as User, then you can use the scheduled path to avoid the Mixed DML Exception. The Mixed DML Exception occurs when a transaction attempts to perform DML operations on both setup (e.g. User) and non-setup objects (e.g. Account) within the same context.

Schedule Triggered Flow

A schedule-triggered flow starts at the specified time and frequency for a batch of records. With this feature, you can schedule an auto-launched flow to start at a specific time and set it to run once, daily, or weekly. You can also specify the object and a filter condition so that the set of entry records going into the flow is defined. You can monitor scheduled flows from the Scheduled Jobs page in Setup.

You can use schedule-triggered flow to set up a recurring job which performs some operations on an object of interest. E.g. a job that reviews all accounts daily and sends some notifications to qualifying accounts or a daily job that reviews all open opportunities and creates Tasks based on pre-set criteria. One limitation of schedule-triggered flow right now is that there is no option to change the default batch size of 200. If there are any situations where you need control over changing this batch size, you will need to use scheduled apex.

Scheduled Apex

When the above declarative options are not suitable then you can go for a custom coding option using Scheduled Apex. To invoke Apex classes to run at specific times, first implement the Schedulable interface for the class, then specify the schedule using either the Schedule Apex page in the Salesforce user interface or the System.schedule method. The system.schedule method can be used to provide an expression used to represent the one-time or recurring date time the job is scheduled to run.

The scheduled apex can be used to perform operations similar to scheduled triggered flow. But because of using Apex, you have more control over custom operations. If the processing is to happen on a large number of records then you can call the System.scheduleBatch method to schedule a batch job. You also have control over the batch size when using scheduled batch apex.

Time-Dependent Workflow Action

Another legacy method of scheduling the processing of data is Time-Dependent Action in a workflow. This action is similar to the scheduled path in a record-triggered flow. This is a legacy functionality in Salesforce. Starting in Winter ’23, Salesforce will be blocking the creation of new workflow rules. You can still activate, deactivate, and edit any existing workflow rules. For any new similar scheduling requirements, use a scheduled path in a record-triggered flow.

To Sum Up

Automating recurring workflows, especially those that have to happen on a set schedule, usually reduces administrative overhead for users. Push notifications, if done right, increase the value of the system to the user. Both of these go a long way in improving the adoption of Salesforce within your organization.

Shailesh Bhide
Shailesh Bhide
Shailesh is a Principal at Varasi. He shares thoughts and insights on technical know-how and patterns that helps us build elegant Salesforce solutions for our customers. He is passionate about leveraging the Salesforce platform to its full potential.