Loading
Salesforce now sends email only from verified domains. Read More
Business Rules Engine
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Monitor Guardrail Limits with Apex

          Monitor Guardrail Limits with Apex

          Fetch and monitor guardrail limits for your org using an Apex class. You can also invoke the Apex class in a flow.

          Required Editions

          Available in: Lightning Experience
          Available in: Enterprise, Unlimited, and Developer Editions for clouds that have Business Rules Engine enabled

          Create three Apex classes to fetch and list guardrail limits for your org.

          APEX Class Description
          GuardrailOutput Represents a single guardrail with various properties such as type, name, notification support, and value limits. It is designed to be used in Salesforce processes, flows, or Lightning components.
          GuardrailListOutput Represents a list of GuardrailOutput objects. It is used to group multiple guardrails together, making it easier to handle collections of guardrails in processes, flows, or Lightning components.
          GuardrailAPI Provides the invoke method to retrieve guardrail information for a list of components. The invoke method calls the getBREGuardrails method from the ConnectApi.BreGuardrailFamily class for each component, processes the results, and returns a list of GuardrailListOutput objects.

          You can use the Apex classes in a scheuled flow to routinely check guardrail

          1. Click the Setup icon, and then click Developer Console.
          2. To create a new Apex class, click File | New | Apex Class.
          3. Create an Apex class with the name GuardrailOutput.

            Here’s a sample Apex code for the GuardrailOutput apex class.

            public class GuardrailOutput {
                @InvocableVariable
                @AuraEnabled
                global ConnectApi.GuardrailTypeEnumRepresentation guardrailType;
                @InvocableVariable
                @AuraEnabled
                global String name;
                @InvocableVariable
                @AuraEnabled
                global Boolean notificationSupported;
                @InvocableVariable
                @AuraEnabled
                global String minValue;
                @InvocableVariable
                @AuraEnabled
                global String maxValue;
                @InvocableVariable
                @AuraEnabled
                global String limitValue;
                @InvocableVariable
                @AuraEnabled
                global String currentValue;
            }
                 
          4. Create another Apex class with the name GuardrailListOutput.
            Here’s a sample Apex code for the GuardrailOutput Apex class.
            public class GuardrailListOutput {
                @InvocableVariable
                @AuraEnabled
                global List<GuardrailOutput> guardrails;
            }
                 
          5. Create another Apex class with the name GuardrailAPI.
            Here’s a sample Apex code for the GuardrailOutput Apex class.
            public class GuardrailApi {
                @InvocableMethod()
                global static List<GuardrailListOutput> invoke(List<String> components) {
                    List<GuardrailListOutput> allRes = new List<GuardrailListOutput>();
                    for(String component : components) {
                        ConnectApi.BreGuardrails result = ConnectApi.BreGuardrailFamily.getBREGuardrails(component, true);
                        GuardrailListOutput res = new GuardrailListOutput();
                        res.guardrails = new List<GuardrailOutput>();
                        for(ConnectApi.Guardrails guardrailIt : result.result[0].guardrails) {
                            GuardrailOutput go = new GuardrailOutput();
                            go.guardrailType = guardrailIt.guardrailType;
                            go.name = guardrailIt.name;
                            go.notificationSupported = guardrailIt.notificationSupported;
                            go.minValue = guardrailIt.minValue;
                            go.maxValue = guardrailIt.maxValue;
                            go.limitValue = guardrailIt.limitValue;
                            go.currentValue = guardrailIt.currentValue;
                            res.guardrails.add(go);
                            System.debug(go);
                        }
                        allRes.add(res);
                    }
                    return allRes;
                }
                  }
                 
          6. Save your changes.
          7. To send email to users in your org who have reached their guardrail limits, follow these steps:
            1. From Setup, find and select Process Automation Settings.
            2. Set up the workflow user and the organization-wide email addresses for your org.
            3. From Setup, go to Flows.
            4. To create a Schedule-Triggered Flow, click New Flow, then click Scheduled, then click Schedule-Triggered Flow.
            5. Set the Start Date, Start Time, and the Frequency of the flow.
            6. Click Add element, and select the Action element.
            7. In Search Actions, find and select the invocable method created.
            8. Add a loop element to iterate over all the guardrails.
              In the loop section, include the GuardrailListOutput Apex class, and select guardrails that have isNotificationEnabled set to True.
            9. Add a decision element to check if a guardrail has reached its limit and generate a text.
            10. After the loop ends, add a Send Email element to send an email.
           
          Loading
          Salesforce Help | Article