Trigger Configuration Basic Example

Below steps describes how we can create Trigger configuration and run it.


Step 1: Create Apex Trigger

First we need to create a trigger class. For that we can use Generate Trigger Code functionality provided in the triggers menu. Simply go to Breezz SetupTriggersGenerate Trigger Code.

Create apex trigger Create apex trigger

Pick Account and Before Insert trigger event. Next, just click on Copy to Clipboard.

1trigger AccountsTrigger on Account (after delete, after insert, after undelete, after update, before delete, before insert, before update) {
2    forvendi.BreezzApi.TRIGGERS.handle();
3}

Your code should look like the one provided above. Next you need to create trigger class in your IDE or Developer Console. To create in Developer Console go to SetupDeveloper ConsoleFileNewApex Trigger.

To know more about Salesforce Triggers please check the Salesforce Trigger Documentation.


Step 2: Create Step Class

Lets start from Step class creation, we can use our well known logic which perfectly fetches Before Insert/ Update triggers. You can read more about this here.

 1// class need to extends forvendi.Step class
 2public with sharing class UppercaseNameFieldStep extends forvendi.Step {
 3
 4
 5    // public default constructor need to available2
 6    public UppercaseNameFieldStep() {
 7        // for the technical reasons we have to pass the class name -
 8        // without this, the framework will not be able to execute this step in async context and create correct logs
 9        super(UppercaseNameFieldStep.class.getName());
10    }
11
12
13    public override Boolean initRecordProcessing(Object record, Object optionalOldRecord) {
14        // we can cast record parameter to SObject because step we are planning to pass list of Accounts
15        SObject sfRecord = (SObject)record;
16        String recordName = (String)sfRecord.get('Name');
17
18
19        sfRecord.put('Name', String.isBlank(recordName) ? '' : recordName.trim().toUpperCase().replace(' ', '_'));
20
21
22        // returning false - because we have all what we need to finish the process
23        return false;
24    }
25}

This class makes some simple changes in the SObject Name field. After successfully deploying you can go to the next step.


Step 3: Add Step Group

Now we have to create Step Group. Go to Breezz App → click Breezz SetupDashboardCreate Group.

Add step group Add step group

Name and description should be meaningful. If group is created only for trigger maybe the good idea would be to use the same Label/Name as in Trigger Config.


Step 4: Register Step

After creating the Step Group you could register the Step in Step Group. To create Step go to Breezz SetupStep Groupschoose previously created groupClick New Step.

Configure new step Configure new step


Step 5: Create Trigger Configuration

The last step is to register our Step Group as a Trigger Handler. To create Trigger Configuration go to Breezz SetupTriggersNew or simple create Trigger config from Dashboard.

Register new trigger Register new trigger

Choose object name, for out purpose it will be Account. Select type of event which will be Before Insert (just as trigger we created in Trigger Configuration bacis example - Step 1) as we want to edit Account information before committing changes to database. Next input Order of execution. Name of trigger config should be meaningful. After picking Object and Trigger Event Type the Name field will be provided with autogenerated value combined of two previously mentioned inputs. It is highly recommended that trigger config names are abundantly clear i.e. good idea could be to put the object name, record type (or something else that describes record split rule) and event name as a part of the Name. You can read more about trigger configuration in Breezz Trigger Config section.

Next Create Default Step Group will be set to no as we previously created a group for purposes of this trigger config, pick Step Group from Step 3: Add Step Group. The trigger is executing Groups one by one to provide correct separation between Steps execution. Each group is working in its own separated execution context (DataStore, Modification Context). Splitting functionalities execution in the multiple groups is highly sub-optimal - please try to run logic using only one group. Click save and go to the next step of our configuration.


Step 6: Test Breezz Trigger

After completing all previous steps go to App LauncherAccounts → create new Account go to the right corner click New → Input name and click save.

Create new account Create new account

As we can see our name was changed successfully!

Created account Created account