Example Usage

Below steps describe how we can create a simple Feature Flag and use it.


Step 1: Configure new Feature Flag

Follow the steps from Feature Flag configuration and create a new Feature Flag with the data as below:

NameFixer Feature Flag NameFixer Feature Flag

We can use more complex configuration in this window:

  • Custom Permission Name - we can create custom permission and specify which users to give access to by assigning it to permission set on user profile. Then we can add this Custom permission name to the field.
  • Feature Flag Field - we can create a feature flag in custom settings and then we can assign to the profile we want by using the checkbox. Then all users with that profile will have access.
  • Use Feature Toggle Service Plugins - we can choose to use feature toggle service or not. This interface specifies that the feature toggle is enabled or disabled.

Step 2: Create Step class

Let’s start from Step class creation.. You can read more about this here.

 1// class need to extends forvendi.Step class
 2public with sharing class NameFixerStep extends forvendi.Step {
 3
 4
 5    // public default constructor need to available
 6    public NameFixerStep() {
 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(NameFixerStep.class.getName());
10    }
11
12
13    public override Boolean initRecordProcessing(Object record, Object optionalOldRecord) {
14
15
16        // we can cast record parameter to SObject because step we are planning to pass list of Accounts
17        SObject sfRecord = (SObject)record;
18        String recordName = (String)sfRecord.get('Name');
19
20
21        // using Modification Context to save changes in the database
22        getContext().addModificationToUpdate(
23                sfRecord.Id,
24                Account.Name,
25                (String.isBlank(recordName) || recordName.contains('FIXED')) ? recordName : recordName + 'FIXED');
26
27
28        // returning false - because we have all we need to finish process
29        return false;
30    }
31}

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


Step 3: Create a test method for the Step class.

You can read more about how to tests Step here How to test Step.

Here we have a test method to our Name Fixer step.

 1@IsTest
 2private class NameFixerStepTest {
 3
 4
 5    @TestSetup
 6    static void testSetup() {
 7        // initializing Breezz setup,
 8        // you have to provide forvendi.BreezzPlugins.BaseApexPlugin
 9 implementation if you would like to
10        // use public classes like UppercaseNameFieldStep in Breezz
11        forvendi.BreezzApi.TESTS.init('BreezzPlugin');
12    }
13    @IsTest
14    static void Should_createRecordWithFixedAddedToName() {
15
16
17        Account acc = new Account(Name = 'Ms_Smith');
18        List<Account> accs = new List<Account>{acc};
19       
20        Test.startTest();
21        insert accs;
22        forvendi.BreezzApi.STEPS.build()
23        .addStep(new NameFixerStep())
24        .execute(accs);
25        Test.stopTest();
26
27
28        forvendi.BreezzAPI.TESTS.assertErrorLogs();
29        acc = (Account)forvendi.BreezzAPI.TESTS.loadRecordById(acc.Id);
30
31
32        Assert.isNotNull(acc);
33        Assert.areEqual('Ms_SmithFIXED', acc.Name);
34    }
35}

Step 4: Register Step

In this example I will use after insert trigger on account.

To create Step go to Breezz SetupStep Groupschoose a previously created group → Click New Step.

Feature Flag Step Config Feature Flag Step Config

Important thing here is that we need to add our FeatureFlag that we created previously to the Feature Availability.


Step 5: Test feature flag

After completing all previous steps go to App LauncherAccounts → create a new Account go to the right corner click NewInput name and click Save.

New Account New Account

As we can see our name was changed successfully.

New Account Name New Account Name

If we want to disable this functionality, we just need to go to the Feature Flags in Breezz Setup and we can disable this flag.

Disable Feature Flag Disable Feature Flag