Scheduling a Scenario


Setting up a Scheduled Job allows for Data Synchronization to occur at a set time, allowing for data to be updated automatically in Salesforce from SAP (or other systems). 

 

1. Navigate to the Scheduled Jobs tab (1). Select New Scheduled Job (2).

 

2. Enter a Job Name (1), Frequency (2) and choose your Salesforce connection string for the Connection String (3). Select your Start Date (4)  and the time of day you wish the job to run in the Hours (5) and Minute (6) fields. If you need to limit how long you would like the job to run, you can enter an End date (7). In this example, we chose a "Weekly" Frequency, in off-peak hours at 1:00 a.m. 

 

When a scenario is run manually, Overcast executes in that user's context or session. Since scheduled jobs occur without user interaction, a connection string that specifies a Salesforce account is necessary for the scheduled job to run properly. See details on creating a connection string here.

3. Scroll Down to the Frequency Section. If you chose a frequency of "Weekly" above in step 2 (2), enter the week day that the scheduled job should run under the Frequency: Weekly (1) section. If you chose a frequency of "Monthly", enter the details regarding the schedule in the Frequency: Monthly (2) section. Select Save (3) after you have populated the section that corresponds with your choice for Frequency.

 

Frequency:Monthly 
Check Use Numbered Days (1) and select Numbered Day (2) to indicate on which particular day of the month you would like the job to run, or alternatively, select Week of the Month (3) and Day of the Week (4) pair to indicate on which particular day of which particular week the job should run. You would choose one of the pairs to set up your schedule on a monthly basis. 
When scheduling the Overcast Scheduled Job, the job is submitted to the Salesforce scheduler as the active user. If this user gets deactivated, the scheduled jobs will not run. To avoid this, log in and schedule the job as the technical/integration user that is stored in the Salesforce Job Connection String. 


Create a Scheduled Task

A Scheduled Task associates an Integration Scenario with the Scheduled Job.

1. Now that the Scheduled Job is created, scroll to the Scheduled Tasks section. Select New Scheduled Task.

 

2.  Enter a Task Name for the Scheduled Task (1). The Description field is optional. Note that your Scheduled Job is already populated and it is marked Active. Under Scenario Settings, select the Data Synchronization Integration Scenario you just created for your Scenario (2), select "Read" for the Operation field (3), and enter the name of the Query Predicate (for read) or Data Set (for create/update/delete) into the Scenario Input field (4). Select Save (5).

 

You must enter the Scenario Input name exactly how it is spelled on your Query Predicate Name, located in your Data Synchronization Integration Scenario. 

 

3. Select Test Job on the Scheduled Job record to ensure it will work correctly. Note that Test Job runs the integration, so records will be modified and data updated; changes are not rolled back.



4. Click Schedule this Job to submit the job to the system scheduler.

 

5. Confirm that the Job Status changes to "Scheduled".


 

6. Scenario "DataSynchronization_Account" will run with Scenario Input "Account Nr. 1001-1500" at 1:00 a.m. weekly on Sunday starting from 7/7/2020 until you select Unschedule this Job.

 

Troubleshooting Scheduled Jobs

When a user schedules a job on Overcast Scheduled Jobs, the job is added to Salesforce Scheduled Jobs list, which will start the Apex job.

 

There may be times when a Scheduled Job fails to run but it does not appear in the Monitoring tab. If this occurs, navigate to Setup > Quick Find and search for "Scheduled Jobs". By selecting that tab, you will land on a list of all Scheduled Jobs in your org, including Overcast scheduled jobs. You can then see if the job was successfully submitted, started, and when the next run will take place. 

 

If you need to see a more technical display of the Status, Batches Processed, or Failures, navigate to Setup > Quick Find and search for "Apex Jobs" to see all of the logs of jobs run by Salesforce Scheduled Jobs.

 

It is recommended to space out the start times of scheduled jobs to minimize issues that occur when too many are triggered at once. Also, it is recommended to break large jobs into smaller jobs, by utilizing Data Sets to reduce the number of records that are retrieved at once.


Scheduling Apex Code

The standard way to schedule Apex code is using the Salesforce cron scheduling. An alternative method is to use the code provided below. In order to execute Apex code when a scheduled task is run, implement the interface provided, insert the records into the database to create the Data Set, and call the helper method executeScenarioForThisTask to run the scenario.

global class RunTaskCode 
implements overcast.ScheduledCalloutHandler.DynamicCodeExecutor {

    global void run(overcast__ScheduleTask__c task, 
        Overcast.ScheduledCalloutHandler.DynamicCodeHelper helper) {
        string datasetname = system.now().format();
        // Create records for the data set below.

        helper.executeScenarioForThisTask(datasetname);
    }
}

 

You can schedule any code this way to avoid using the standard cron scheduler.

The helper parameter contains information about the Scheduled Job that was executed, the ID of the current Scheduled Job and information about the Task's Scenario and execution parameters.

 

After saving your class, create a new task attached to the job. In the Custom Code Execution Settings section, select the checkbox for Don't Execute Scenario (1) and enter "RunTaskCode" into the Class Name field (2). Select Save (3).

If both "Autolaunched Flow Name" and "Class Name" are specified, note that the Autolaunched Flow will be run only after the dynamic Apex execution class has finished execution. This means that in the event that the Apex class throws an exception, Flow execution will be skipped.

 

Selecting "Don't Execute Scenario"(1) will prevent the Scheduled Task from executing normally (i.e, execute the scenario with the provided operation and input). At least one alternate method of scenario execution must be provided when set (either Dynamic Apex code, or an Autolaunched Flow).

Scheduling an Autolaunched Flow (Run Scenarios Sequentially)

If scheduling sequential Scenario Executions is required, the best solution is to schedule an Autolaunched Flow. Apex code on its own is unable to wait for one particular scenario run to finish before starting the next one. To work around this limitation, Overcast provides a Flow Action which will execute a particular scenario but only after a specified previous scenario run is finished. When scheduling an Autolaunched flow for use within a task, it takes the same inputs as a Dynamic Apex task.

 

1. Create a new Flow and under the categories select Autolaunched Automations and select type: Autolaunched Flow (No Trigger)

2. Toggle the toolbox (1) on the left and under Manager (2) select New Resource (3).

 

3. Select Resource Type to Apex Defined (1), API Name (2) to inputsFromScheduledTask (case-sensitive) and Data Type (3) to Apex Defined, Apex Class as overcast__AutoLaunchedTaskFlowInputs (4) then check Available for input (5).

4. As an example, we will set up two Data Sync Scenario Runs where the second waits for the first.

5. Add a new element: Run Overcast Data Sync Scenario

7. Fill Scenario NameOperation and Scenario Input (query predicate name) with whatever is desired for a scenario execution (Scenario Input should be set to manual to specify a particular input).

8. Add a new element: Run Overcast Data Sync Scenario with Wait

9. Specify Scenario Flow Action (1) with the scenario to wait for. A dropdown menu populated with scenarios listed elsewhere in the flow will be present. Specify whether the action is waiting for the read step or mapping step to complete and action on error (2). Fill out the other fields (3) the same way as the first query.

 

10. Save and activate the flow when finished, return to the scheduled job page and create or edit a scheduled task. Check the Don't Execute Scenario (1) box, otherwise the task will also execute a scenario at the same time the flow is launched. Specify Autolaunched Flow Name (2), ensure the name matches the flow exactly, otherwise an error will be displayed. Class Name may also be specified to run Apex code simultaneously on flow execution.

Scenario settings must also be filled out. As long as Don't Execute Scenario is checked, these inputs will only be used as input parameters for the Autolaunched Flow.

11. On the scheduled job detail page click Test Job in order to verify the task is working correctly. You should see on the monitoring page that the next scenario will only start when the preceding one is finished.

---

User Maintenance

Overcast Scheduled Jobs run on top of the Salesforce scheduler under the user who scheduled the job. When a user is disabled, all scheduled jobs scheduled under that user get deactivated, and manual maintenance is required.

The steps to reassigning the jobs to another active user are

  1. Identify all Overcast Scheduled Jobs that are scheduled by the disabled user by either 
    1. Find all Overcast Scheduled Jobs with the field Last Modified By the disabled user; or
    2. In Setup -> Environments -> Jobs -> Scheduled Jobs, find all jobs with the field Submitted By the disabled user. The job name matches the Overcast Scheduled Job name.
  2. On each Overcast Scheduled Job, click the Unschedule this Job button.
  3. Click the Schedule this Job button.

Now the scheduled job is running as the active user.

 

Additionally, to avoid performing this process each time a user is disabled, log in to Salesforce as the technical/integration user and schedule jobs through it.