Custom
On this page, you can find an example of building a custom type job scheduler.
Step 1: Create Apex Class
You can easily generate groundwork for your custom scheduler job with Generate Scheduler Code.
Go to Breezz App → Breezz Setup → Scheduler Jobs → Generate Scheduler Code. Select Job Type for now we will use Custom Job, pick a class name and copy code to your IDE or Developer Console.
Let’s implement a simple job which will be executed every 30 minutes and create 5 account’s.
1public with sharing class AccountRecordsGenerator implements forvendi.SchedulerJob{
2 public AccountRecordsGenerator init (forvendi.SchedulerJobInfo schedulerConfig){
3 return this;
4 }
5
6 public Boolean shouldRun(){
7 return true;
8 }
9
10
11 public void run(){
12 // use database to insert 5 new accounts
13 List <Account> accounts = new List<Account>();
14 for(Integer i = 0; i < 5; i++){
15 accounts.add(new Account(Name = 'Account ' + System.now() + ' | Number ' + i));
16 }
17 Database.insert(accounts);
18 }
19}
The class which will be used in Scheduler must implement forvendi.SchedulerJob and need to have 3 methods.
Method init() which returns an instance of class.
Method shouldRun() decides whether the job is to be executed or not.
Method run() in which we have the logic of our job.
So at the inside of class we have a for loop, which adds a new Account to the list and after all iterations account’s will be inserted by Database.insert().
Step 2: Create Test Class
1@IsTest
2private class AccountRecordsGeneratorTest {
3
4
5 @TestSetup
6 static void testSetup() {
7 // initializing Breezz setup,
8 // you have to provide forvendi.BreezzPlugins.BaseApexPlugin implementation if you would like to
9 // use public classes like UppercaseNameFieldStep in Breezz
10 forvendi.BreezzApi.TESTS.init('BreezzPlugin');
11 }
12
13
14 @IsTest
15 static void when_ExecutedAccountRecordsGenerator_expect_GenerateAccounts() {
16
17
18 // execute logic inside class that implements forvendi.SchedulerJob
19 Test.startTest();
20 forvendi.BreezzApi.SCHEDULER.run('AccountRecordsGenerator');
21 Test.stopTest();
22
23
24 List<Account> accs = forvendi.BreezzApi.TESTS.loadAllRecords(Account.getSObjectType());
25 forvendi.BreezzAPI.TESTS.assertErrorLogs();
26
27
28 Assert.isNotNull(accs);
29 Assert.isTrue(accs.size() > 0);
30 }
31}
Step 3: Register Scheduler Job
After successfully deploying we can configure Scheduler. Go to: Breezz Setup → Scheduler Jobs → Click New.
Now we need to input Name and add some Description and select the type of Scheduler Job. In our case it will be Custom. Next select Execution Interval – 30 minutes. Lastly pick a class which implements forvendi.SchedulerJob you created or the one provided above.
Step 4: Check Scheduler Job
To check if a scheduler was created go to App Launcher → Breezz → Breezz Scheduler Jobs → All Custom Jobs.
Here you can see your Scheduler: