Are you leveraging the power of Salesforce Agentforce Sales Coach? This innovative feature empowers sales teams with AI-driven insights and coaching, directly within the Salesforce platform. But for administrators and developers, a common question arises: how can you programmatically determine if Agentforce Sales Coach is actually enabled in a given Salesforce org?
While you can manually check for the “Agentforce Sales Coach” permission set in the Salesforce UI, situations often call for an automated, Apex-based approach. This is particularly useful for:
- Conditional Logic in Apex: Executing specific code paths only when Sales Coach is active.
- Automated Audits & Health Checks: Reporting on feature enablement across multiple orgs.
- Package Development: Ensuring your managed package behaves correctly based on org configurations.
The good news is that Salesforce provides a reliable way to do this by inspecting the presence of a specific, system-generated Permission Set.
The Key: The “EinsteinCoachAgent” Permission Set
When Salesforce Agentforce Sales Coach is enabled in an org, Salesforce automatically creates a special Permission Set. This Permission Set has a unique API Name that we can target in our Apex queries:
- API Name:
EinsteinCoachAgent - Label:
Agentforce Sales Coach
Crucially, this Permission Set is not custom; it’s a standard Permission Set generated by Salesforce itself upon feature activation. This distinction is important for our Apex query.
Apex Code to Detect Agentforce Sales Coach
Here’s the elegant and efficient Apex code snippet you can use to check for the presence of the EinsteinCoachAgent Permission Set, thereby confirming if Salesforce Agentforce Sales Coach is enabled:
Sample Apex Code:
Integer intSalesCoachCount = [
SELECT COUNT()
FROM PermissionSet
WHERE Name = 'EinsteinCoachAgent'
AND IsCustom = false
];
if ( intSalesCoachCount > 0 ) {
System.debug( 'Salesforce Agentforce Sales Coach is ENABLED.' );
// Your Apex logic when Sales Coach is enabled
} else {
System.debug( 'Salesforce Agentforce Sales Coach is DISABLED.' );
// Your Apex logic when Sales Coach is disabled
}
Let’s break down this code:
SELECT COUNT() FROM PermissionSet: We’re performing a SOQL query on thePermissionSetobject to count matching records.WHERE Name = 'EinsteinCoachAgent': This is the crucial filter. We’re specifically looking for the Permission Set with the API NameEinsteinCoachAgent.AND IsCustom = false: This condition is vital. It ensures that we are only looking for standard, system-generated Permission Sets, preventing false positives from any custom Permission Sets that might coincidentally share a similar name.if ( intSalesCoachCount > 0 ): If the query returns a count greater than zero, it means theEinsteinCoachAgentPermission Set exists, and thus Salesforce Agentforce Sales Coach is enabled.
Why This Method is Reliable
- Direct Salesforce Mechanism: This method relies on a standard Permission Set automatically provisioned by Salesforce when the feature is activated.
- Future-Proof (within reason): While Salesforce could theoretically change the API name in a major platform update, this is generally unlikely for core feature enablement mechanisms without prior notice.
- Efficient: A
COUNT()query is highly efficient and doesn’t retrieve unnecessary record data, making it suitable for various Apex contexts.
Implementing This in Your Org
You can incorporate this Apex code into various parts of your Salesforce development:
- Apex Triggers: To modify behavior based on Sales Coach enablement.
- Apex Classes: As a utility method to be called from other services.
- Visualforce Pages or Lightning Web Components: To conditionally display UI elements.
- Scheduled Apex: For regular checks or reporting.
By using this simple yet powerful Apex snippet, you can confidently and programmatically determine the enablement status of Salesforce Agentforce Sales Coach in any Salesforce org, empowering you to build more intelligent and adaptive Salesforce solutions.