Skip to content
Custom Split Strategy

Custom Split Strategy

The Custom Split Strategy enables developers to route trigger logic based on custom Apex logic.

This example shows how to use Breezz Triggers to display an error message if a new Case is closed and the Resolution Notes custom field is left empty.

Step 1: Create a Trigger

While you can create a Trigger in several different ways, this example walks through creating one with the Breezz Environment Graph.

ℹ️ For more information about other ways of creating Triggers refer to the Triggers Configuration section.

  1. Navigate to the Breezz Environment Graph.
  2. Within the Breezz Environment Graph, select Trigger and choose Case.

Create Trigger

  1. Click the Trigger Icon.

ℹ️ Note: For additional information regarding the Breezz Environment Graph, please refer to the Environment Graph section.

Create Trigger Form

  1. Populate the configuration form with the following details:
  • Trigger Event: Select Before Insert or another event that should fire the trigger.
  • Records Split Strategy: Select Custom.
  • Records Split Strategy Class: Click the Plus Icon to add new Apex Class.

If you haven’t created a Salesforce Trigger yet click the Generate Trigger Code button.

ℹ️ For more information about Generate Trigger Code button refer to the Triggers Configuration section.

Custom Split Strategy Form

  1. Paste following code into the Class section.
global class ClosedCaseSplitStrategy implements TriggerRecordsSplitStrategy {
    
    global Boolean canProcess(SObject record, SObject optionalOldRecord) {
        // Cast generic SObjects to the specific Case type
        Case newCase = (Case) record;
        Case oldCase = (Case) optionalOldRecord;
        
        // Check if the current status is 'Closed'
        Boolean isNowClosed = (newCase.Status == 'Closed');
        
        // Check if the previous status was different than 'Closed'
        Boolean wasNotClosedBefore = (oldCase.Status != 'Closed');
        
        // The record will be processed only if both conditions are met
        return isNowClosed && wasNotClosedBefore;
    }
}
  1. Paste following code into the Test class section.
@IsTest
private class ClosedCaseSplitStrategyTest {
    
    @IsTest
    static void testStrategyConditions() {
        ClosedCaseSplitStrategy strategy = new ClosedCaseSplitStrategy();
        
        // Status changed to 'Closed' -> TRUE
        System.assertEquals(true, strategy.canProcess(new Case(Status = 'Closed'), new Case(Status = 'In Progress')));
        // Updating a record that was already 'Closed' (e.g. editing another field) -> FALSE
        System.assertEquals(false, strategy.canProcess(new Case(Status = 'Closed'), new Case(Status = 'Closed')));
    }
}
  1. Click Deploy.

Custom Split Strategy Form Deployed

  1. Select the ClosedCaseSplitStrategy class that you just deployed.

  2. Click Save.

Step 2: Create a Step for the first Record Type

  1. In the Breezz Environment Graph click the Action Icon o the Step Group.

Enrivonment Graph Action Icon

  1. Select Create Step.

Enrivonment Graph Create Step Configure New Step

  1. Populate the configuration form with the following details:
  • Parent Group: Provide a name for the step.
  • Description: Provide a brief description of the step.
  • Entry Criteria: Select Resolution Notes custom field and Is Not Set.
  • Action Configuration: Select Custom Validation.
  • Choose From: Choose Plaint Text.
  • Error Message: Provide an error message, eg. You cannot close this Case without entering Resolution Notes. Please fill out the field and try again..
  1. Leave the rest as it is and click Save.

Step 3: Verify the result

  1. Create a Case with any data and leave the Resolution Notes field empty.
  2. Try to close this Case to see the custom error message.

Close Case Result