You are here:
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
- Click the Setup icon, and then click Developer Console.
- To create a new Apex class, click File | New | Apex Class.
-
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; } -
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; } -
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; } } - Save your changes.
-
To send email to users in your org who have reached their guardrail limits, follow these steps:
- From Setup, find and select Process Automation Settings.
- Set up the workflow user and the organization-wide email addresses for your org.
- From Setup, go to Flows.
- To create a Schedule-Triggered Flow, click New Flow, then click Scheduled, then click Schedule-Triggered Flow.
- Set the Start Date, Start Time, and the Frequency of the flow.
- Click Add element, and select the Action element.
- In Search Actions, find and select the invocable method created.
-
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.
- Add a decision element to check if a guardrail has reached its limit and generate a text.
- After the loop ends, add a Send Email element to send an email.
Did this article solve your issue?
Let us know so we can improve!

