You can apply business policy at regular times (for instance hourly, daily or weekly) using a Scheduled Invocation. 


You might use a Scheduled Invocation to run a business policy:

  • Every hour during the week to assign stale Leads to new owners
  • First thing Monday morning to distribute the Leads that were created over the weekend
  • Every week or month to move unresponsive leads to a queue


A Scheduled Invocation can be set to run on any schedule allowed by Scheduled Apex (see the Using the System.Schedule Method in the Salesforce documentation here). Note that this doc is not entirely accurate: the maximum frequency to run a job is actually hourly (not daily) -- in other words you can use the 'Special Characters' like * and ranges for the Hours part as well. You can also set up a series of Scheduled Invocations at different start times to run the same business policy multiple times an hour. Note: Salesforce only allows 100 scheduled Apex jobs to be active at one time.


If you need to apply a policy at shorter intervals (as often as every minute) you can use a Periodic Invocation instead.


Creating a Scheduled Invocation for your business policy

To schedule a regular invocation of a specific policy, go to the Scheduled Invocations section on the policy detail page. Select 'New Invocation' 


You can enter the following:

  • Where Clause
    • This (optionally) allows you to select a subset of records to which the policy will be applied.
      For example, Industry = ’Insurance’ will select only records with the Industry field set to 'Insurance'.
    • The format of the where clause is defined by the SOQL language, see here for details.
    • To validate the syntax of your WHERE clause, press the Tab key or click outside of the text box.
  • Send email on completion?
    • Whether you would like to receive an email when the job completes or only if there is a failure or not at all.
  • Create execution record?
    • Whether you would like to create an execution record for the invoked records.
  • Batch Size
    • This specifies the number of records to process in one call to the Decisions on Demand server.

    • The default is 50 which works well for most cases. If you experience issues with governor limits you can reduce this to 25 or 10. 

    • If you need to speed up your processing you can try higher values -- the maximum is 2000.

  • Schedule

    • This field determines the start day and time as well as the frequency of the Scheduled Invocation run.

    • The format is defined by the Apex Scheduler: Seconds Minutes Hours Day_of_month Month Day_of_week Optional_year

    • For more information please see the Apex Scheduler documentation
      The section Using the System.Schedule method explains the syntax for setting the schedule.
      Note that (contrary to what the Salesforce doc states) you can actually use 'Special Characters' like * and ranges for the Hours part as well, allowing you to run jobs on an hourly basis

  • Sample Schedule expressions

    • Selecting one of these picklist values will populate the Schedule field with some commonly used schedules (the schedule expression is shown in bold)

      • Hourly at the 0th minute - Every hour at the top of each hour - 0 0 * * * ?

      • Hourly at the 15th minute - Every hour at 15 minutes after the hour - 0 15 * * * ?

      • Hourly at the 30th minute - Every hour at 30 minutes after the hour - 0 30 * * * ?

      • Hourly at the 45th minute - Every hour at 45 minutes after the hour - 0 30 * * * ?

      • Hourly from 8 to 11 am at 15 minutes past the hour  - 0 15 8-11 * * ?

      • Daily at midnight - 0 0 0 * * ? *

      • Daily at 1 AM - 0 0 1 * * ? *

      • Daily at 6 PM - 0 0 18 * * ? *

      • Daily Monday through Friday at 10 AM - 0 0 10 ? * MON-FRI

      • Weekly at Monday 8 AM - Every week on Monday at 8 AM - 0 0 8 ? * 2 *

      • Weekly at Sunday Midnight - Every week at 12 PM between Saturday and Sunday - 0 0 0 ? * 1 *

      • Monthly at 15th Day 10:15 AM - Once a month on the 15th at 10:15 AM - 0 15 10 15 * ?

      • Monthly at last Friday 10 PM - Last Friday of the month at 10 PM - 0 0 22 ? * 6L


The example below schedules the invocation of a policy where the DecsOnD__Assignment_Status__c field is set to 'Ready', email is not sent on completion, execution records are created, on a batch size of 50, and it runs hourly at the beginning of the hour:


Managing a Scheduled Invocation

The newly scheduled job will appear in the Scheduled Invocations tab with a status of Scheduled:

You can also see the underlying Salesforce scheduled job: go to Setup and type 'Scheduled Jobs' into the Setup Quick Find box and then select it


The Scheduled Invocation will be visible along with all reporting snapshots, scheduled Apex jobs, and dashboards scheduled to refresh in the organization. Depending on how many jobs there are in the organization there might be scheduling conflicts that will delay the Scheduled Invocation until prior jobs have completed. A maximum of 100 jobs are allowed per organization.


Once the Scheduled Invocation has run the information on the Business Policy Tab will update: 


From the Scheduled Invocations you can click on 'View Report' to see the 'Business Policies with Invocation Record' report and from there you can select an Invocation record to see what occurred:


Go to the Batch Invocation Records section on the policy detail page to view all Invocation Records.


Depending on the option selected and the results of the invocation you may also receive an email:


Finally, to stop or pause the job, click the 'Stop' button next to it. You may want to do this if there is maintenance on the system and you do not want the Scheduled Invocation to run while that is occurring.


To restart the Scheduled Invocation simply click the 'Start' button: