Steps Group Scheduler Job
Using Breezz Framework we can schedule Step Group.
Let’s schedule a simple step group.
Step 1: Create Step Group
For starters let’s create a new Step Group.
Go to: Breezz Setup → Step Groups → New Group
Name it ProcessingCases and add a description.
Leave the rest of the fields default and save it.
Step 2: Create Step Class
Create a class and name it CloseInactiveCases.
Remember that you can use the Generate Step Code button for it or make one yourself.
Here’s the code for the class:
1// class need to extends forvendi.Step class
2public with sharing class CloseInactiveCases extends forvendi.Step {
3
4
5 // public default constructor need to available
6 public CloseInactiveCases() {
7 // for the technical reasons we have to pass the class name - without this,
8 // the framework will not be able to execute this step in async context and create correct logs
9 super(CloseInactiveCases.class.getName());
10 }
11
12
13 public override Boolean initRecordProcessing(Object record, Object optionalOldRecord) {
14
15
16 // we can cast record parameter to Case because step we are planning to pass list of Cases
17 Case caseRecord = (Case) record;
18
19
20 // using Modification Context to save changes in the database
21 getContext().addModificationToUpdate(
22 caseRecord.Id,
23 Case.Status,
24 (caseRecord.Status.contains('Closed')) ? caseRecord.Status : 'Closed');
25
26
27 // returning false - because we have all we need to finish process
28 return false;
29 }
30}
Step 3: Create Test Class
Our next step is to create a test method for our new Step Class.
Here’s the code for the method:
@IsTest
private class CloseInactiveCasesTest {
@TestSetup
static void testSetup() {
// initializing Breezz setup,
// you have to provide forvendi.BreezzPlugins.BaseApexPlugin implementation if you would like to
// use public classes like CloseInactiveCases in Breezz
forvendi.BreezzApi.TESTS.init('BreezzPlugin');
}
@IsTest
static void when_CaseIsInactive_expect_ChangeStatusToClosed() {
Case caseRecord = new Case(Status = 'Working', Origin = 'Web');
List<Case> cases = new List<Case>{caseRecord};
Test.startTest();
insert cases;
forvendi.BreezzApi.STEPS.build()
.addStep(new CloseInactiveCases())
.execute(cases);
Test.stopTest();
forvendi.BreezzAPI.TESTS.assertErrorLogs();
caseRecord = (Case) forvendi.BreezzAPI.TESTS.loadRecordById(caseRecord.Id);
Assert.areEqual('Closed', caseRecord.Status);
}
}
Step 4: Register Step
We need to create a new Step in the ProcessingCases group.
To create new Step go to Breezz Setup → Step Groups → ProcessingCases → Click New Step.
Step 5: Register Scheduler Job
To add Step Group to Scheduler go to Breezz Setup → Scheduler Jobs → click New.
After getting records from the query from Scheduler will update the status field on Cases where the last modified date is more than 7 days ago.
Input Name for Scheduler Job and a comprehensive Description. For Job Type select Step Group. Execution Interval selects the time when scheduler must be executed, for us it’s Sunday midnight. In the Step Group input the name of Step Group. In SOQL Query use SELECT statement to return records on which you want to work.
Step 6: Check Scheduler Job
You can re-run Scheduler manually from apex. Using Developer Console → Open Execute Anonymous Window:
forvendi.BreezzApi.SCHEDULER.rerun();
Or
forvendi.BreezzApi.SCHEDULER.run(CloseInactiveCases);
Or you can Run Manually in Scheduler Jobs Settings in Scheduler Jobs.
To check if a scheduler has been created go to App Launcher → Breezz → Breezz Scheduler Jobs → All Custom Jobs.
Here you can see your Scheduler:
Steps Group Scheduler Job is designed to work with fewer records and to work more frequently. To work with more records, e.g. 10,000. We should use Steps Group - Batch, which is described in the next page.