Child Record Creation Not Present

Breezz framework allows for creating custom data loader logic. For example, let’s take a situation where a customer support system provides a way to generate tasks assigned to Case records when certain business logic is met. But every time the status of the case is changed, the scope of work is different. So naturally we want to close previous tasks, set new goals and get to work. Custom Data Loader solution below allows for gathering tasks linked with a certain Case record and as a result creates parameters that will be used inside our custom logic class.


Step 1: Create Custom DataLoader solution

Create class that implements DataLoader interface just like this one below

 1public class CaseTasksLoader extends forvendi.DataStore.Loader {
 2   
 3    public CaseTasksLoader() {
 4        super('CaseTasks', false);
 5    }
 6
 7
 8    public override void load(forvendi.DataStore store) {
 9        if (store.notInStore(storeKey)) {
10            Map<Id, List<Task>> tasksByCaseId = new Map<Id, List<Task>>();
11            for (Task task : [SELECT Id, WhatId FROM Task WHERE WhatId IN :store.getIds(storeKey)]) {
12                if (!tasksByCaseId.containsKey(task.WhatId)) {
13                    tasksByCaseId.put(task.WhatId, new List<Task>());
14                }
15                tasksByCaseId.get(task.WhatId).add(task);
16            }
17            store.storeData(storeKey, tasksByCaseId);
18        }
19    }
20}

Step 2: Create Breezz Trigger and Trigger Handler

First create a new Apex Trigger on Case object. Go to Breezz Setup -> Triggers -> Generate Trigger Code.

Breezz Trigger Breezz Trigger

Then create Breezz Trigger configuration on Case object with after update context. Make sure Create Default Step Group is set to Yes in order to create Step Group automatically.

Configure New Trigger Configure New Trigger


Step 3: Create Custom Class

Create following apex class that will be used in Breezz Step.

 1public with sharing class CancelAllTasks extends forvendi.Step {
 2
 3
 4    public CancelAllTasks() {
 5        super(CancelAllTasks.class.getName());
 6    }
 7
 8
 9    public override Boolean initRecordProcessing(Object record, Object optionalOldRecord) {
10        // after casting incoming record to case type, check for updates on status field
11        // if any appered use Custom Dataload under 'CaseTasks' storekey and load related tasks
12        Case caseRecord = (Case) record;
13        if (isNewOrChanged(caseRecord, (Case) optionalOldRecord, Case.Status) && caseRecord.Status != null) {
14            getStore().requestToLoad('CaseTasks', caseRecord.Id);
15        }
16        // return true because we want to further edit related records
17        return true;
18    }
19
20    public override void finishRecordProcessing(Object record, Object optionalOldRecord) {
21        // cast both records to gather information from before the update
22        // result of CaseTasksLoader is a Map <Id, List<Task>> so it needs to be casted
23        // and checked for null values just to make sure
24        Case caseRecord = (Case) record;
25        Case oldCaseRecord = (Case) optionalOldRecord;
26        if (getStore().getFromStore('CaseTasks') != null) {
27            Map <Id, List<Task>> loadedCase = (Map <Id, List<Task>>) getStore().getFromStore('CaseTasks');
28        // after the check updates are added to modification contexted and all related tasks are marked as complete
29            if (!loadedCase.isEmpty()) {
30                for (Task tk : loadedCase.get(caseRecord.Id)) {
31                    getContext().addModificationToUpdate(tk.Id, Task.Status, 'Completed');
32                }
33        // create another task to be added to case record to create a follow up about the status change and next steps
34                getContext().addToInsert( new Task(
35                        Subject = 'Follow up on status change, from : ' + oldCaseRecord.Status + ' -> ' + caseRecord.Status,
36                        ActivityDate = System.today().addDays(1),
37                        WhatId = caseRecord.Id,
38                        OwnerId = UserInfo.getUserId()));
39            }
40        }
41    }
42}

Class above gathers all tasks related to Case record that had changes made to them, and check for condition, which here is if status was changed proceed with logic.


Asigning dataloader to the Step: Breezz Setup → Step Groups → select Group → press New Step button.

Breezz Step Breezz Step

Data Loaders Configuration in Group Data Loaders Configuration in Group

There is also possibility to link Custom DataLoader with Breezz Group instead of Breezz Step.

Asigning dataloader to the Group: Breezz Setup → Step Group → click on Group name to open Edit window.

Data Loaders Configuration in Group Data Loaders Configuration in Group