Sure! But I need a bit more information to help you properly.
Could you please share the invocable code or definition you'd like me to explain? In Salesforce, an invocable usually refers to an Invocable Method or Invocable Action, which is used in flows or process builder to call Apex code.
Here are some things I can explain once you share the code:
What the method does
How it's structured (@InvocableMethod, input/output variables)
How it can be used in Flow or Process Builder
Any complex logic or patterns used
Please paste the invocable code, and I’ll walk you through it step by step.
User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
public with sharing class NF_InvocableLoadBalanceHelper {
public class InvocableInput {
@InvocableVariable(required=true description='Developer name of the target we are routing to (e.g. Bot or Queue)')
public String targetDeveloperName;
code
@InvocableVariable(description='Channel Name that the message was received from (e.g. Account Center, vivint.com)')
public String channelName;
}
public class InvocableOutput {
@InvocableVariable(description='When true, calling process should route to the target')
public Boolean canRouteToTarget;
}
@InvocableMethod(
label='Can Route to Target'
description='Gets a Boolean indicating whether or not a process can route a work item to the specified target'
category='Routing'
)
public static List<InvocableOutput> getRouteableResult(List<InvocableInput> inputs) {
InvocableOutput canRoute = new InvocableOutput();
List<Load_Balance_Config__c> loadBalanceConfig = [
SELECT Threshold__c
FROM Load_Balance_Config__c
WHERE Target_Developer_Name__c = :inputs[0].targetDeveloperName
AND Active__c = TRUE
AND Channel_Name__c = :inputs[0].channelName
];
if (loadBalanceConfig.isEmpty()) {
canRoute.canRouteToTarget = false;
} else {
Integer randomNumber = (Integer) Math.floor(Math.random() * 100);
canRoute.canRouteToTarget = randomNumber < loadBalanceConfig[0].Threshold__c;
}
return new List<InvocableOutput>{ canRoute };
}
}
Assistant
Absolutely! Let's walk through this Salesforce Apex class step-by-step and understand what it does, how it works, and why it's structured the way it is.
🔍 Class Overview
apex
public with sharing class NF_InvocableLoadBalanceHelper {
...
}
This is a custom Apex class that contains an invocable method, which can be called from Flow or Process Builder in Salesforce. The with sharing keyword ensures that the class respects the current user’s sharing rules.
🧱 Inner Classes: Input and Output
1. InvocableInput
apex
public class InvocableInput {
@InvocableVariable(required=true description='Developer name of the target we are routing to (e.g. Bot or Queue)')
public String targetDeveloperName;
@InvocableVariable(description='Channel Name that the message was received from (e.g. Account Center, vivint.com)')
public String channelName;
}
This class defines the input variables expected by the invocable method.
It uses the @InvocableVariable annotation so these fields can be passed into the method from Flow or Process Builder.
Two inputs:
targetDeveloperName: Required; identifies the routing target (like a queue or bot).
channelName: Optional; tells where the work item came from.
2. InvocableOutput
apex
public class InvocableOutput {
@InvocableVariable(description='When true, calling process should route to the target')
public Boolean canRouteToTarget;
}
Defines the output returned by the invocable method.
A single output field canRouteToTarget, indicating whether the system should route the current work item to the specified target.
User
where is the threshold set?
Assistant
Great question!
🔧 Where is the Threshold Set?
The threshold value used in this code is set in a custom setting or custom object called:
apex
Load_Balance_Config__c
This line retrieves it:
apex
SELECT Threshold__c
FROM Load_Balance_Config__c
WHERE Target_Developer_Name__c = :inputs[0].targetDeveloperName
AND Active__c = TRUE
AND Channel_Name__c = :inputs[0].channelName
So, the threshold is not hard-coded in the Apex class — it's configurable via Salesforce setup, which makes the logic dynamic and admin-friendly.
🗂️ What Is Load_Balance_Config__c?
It’s likely a custom object (or possibly a hierarchy/custom setting), where admins can define load balancing rules like:
Field
Description
Target_Developer_Name__c
The unique API name of the routing target (e.g., 'SupportBot', 'Tier1_Queue')
Channel_Name__c
The source channel (e.g., 'Account Center', 'Mobile App')
Threshold__c
A percentage (0–100) indicating the probability of routing to this target
Active__c
Boolean flag to enable/disable this rule
🛠️ Example Record
Here’s what a record might look like in the Salesforce UI:
Target Developer Name
Channel Name
Threshold (%)
Active
SupportBot
Account Center
30
Yes
Tier1_Queue
vivint.com
70
Yes
In this example:
30% of work from "Account Center" will go to SupportBot
70% of work from "vivint.com" will go to Tier1_Queue
🎲 How Threshold Is Used
Once the config record is retrieved, the method uses the threshold to determine whether to route:
So if Threshold__c = 40, there's a 40% chance the method returns true.
📌 Summary
✅ The threshold is set in the Load_Balance_Config__c custom object via Salesforce Setup.
🔄 This lets admins change routing percentages without touching code.
🧮 The Apex class reads that value and applies it as a percentage-based routing rule using randomization.
If you want help creating the Load_Balance_Config__c object or populating it with sample data, just let me know!
⚙️ Invocable Method: getRouteableResult
apex
@InvocableMethod(
label='Can Route to Target'
description='Gets a Boolean indicating whether or not a process can route a work item to the specified target'
category='Routing'
)
public static List<InvocableOutput> getRouteableResult(List<InvocableInput> inputs) {
...
}
✅ Purpose:
This method determines if a work item (like a case or chat) should be routed to a specific target (such as a queue or bot), based on a load balancing configuration.
📦 How It Works: Step-by-Step
1. Query Load Balance Config
apex
List<Load_Balance_Config__c> loadBalanceConfig = [
SELECT Threshold__c
FROM Load_Balance_Config__c
WHERE Target_Developer_Name__c = :inputs[0].targetDeveloperName
AND Active__c = TRUE
AND Channel_Name__c = :inputs[0].channelName
];
Queries a custom setting or custom object named Load_Balance_Config__c.
Looks for a record that matches:
Target_Developer_Name__c — the name of the target (bot/queue).
Active__c = TRUE — only active configurations are considered.
Channel_Name__c — the source channel (like "Account Center").
2. Check If Config Exists
apex
if (loadBalanceConfig.isEmpty()) {
canRoute.canRouteToTarget = false;
}
If no matching config exists, then we cannot route to this target.
Compares it to a Threshold__c value from the config.
If the random number is less than the threshold, returns true — meaning "yes, route here".
This implements a percentage-based load balancing strategy.
Example:
If Threshold__c = 40, there's a 40% chance the work will be routed to this target.
📤 Return Value
apex
return new List<InvocableOutput>{ canRoute };
Returns a list of InvocableOutput objects (even though only one is used).
Flows expect lists as input/output for bulkification purposes.
🧪 How Is This Used?
You'd use this in a Flow like this:
Use a Get Records or other element to gather context (target developer name, channel name).
Call this invocable method via the Apex Action element.
Pass in targetDeveloperName and channelName.
Use the canRouteToTarget result to decide whether to assign/route the work item.
🛠️ Key Concepts
Concept
Explanation
@InvocableMethod
Allows Apex methods to be called from Flow or Process Builder.
@InvocableVariable
Marks variables as available for input/output.
Bulk-safe
Accepts and returns lists (though this example only uses the first input).
Randomization
Uses randomness to implement percentage-based routing.
Configuration-driven
Behavior controlled by Load_Balance_Config__c records.
✅ Summary
This class provides a flexible, configurable way to control routing decisions in your automation using percentage thresholds defined in Salesforce. It allows you to dynamically enable/disable routing targets and vary their probability per channel.
Let me know if you’d like help creating the Load_Balance_Config__c object, or want to see how to call this from a Flow!