In the world of Salesforce, efficiency is key, especially when it comes to empowering your service agents. Wouldn’t it be great if your Salesforce Employee Agentforce Agents could automatically get the context they need directly from a record, without having to search or manually input details? This blog post will show you how to achieve exactly that: passing a record ID to your Salesforce Employee Agentforce Agent using Apex Agent Action.
This technique can significantly streamline your agent workflows, reducing the time spent on data entry and improving the overall customer experience. Imagine an agent automatically seeing the case details or account information relevant to a chat, all thanks to a simple ID passed behind the scenes.
Why Pass a Record ID?
- Contextual Conversations: Agents immediately see the relevant record, allowing them to dive straight into problem-solving.
- Reduced Manual Effort: No more copying and pasting IDs or searching for records manually.
- Improved Accuracy: Minimize errors by ensuring the agent is always working with the correct record.
- Faster Resolution Times: Agents can resolve issues more quickly when they have all the information at their fingertips.
The Apex Approach: How It Works
We’ll leverage Apex to dynamically pass the record ID. This involves a few key steps:
- Capturing the Record ID: This typically happens on a Visualforce page, a Lightning Component, or a Flow where the Agentforce chat is initiated.
- Passing to Apex: We’ll use JavaScript to pass the captured ID to an Apex controller method.
- Utilizing the ID in Apex: Once in Apex, you can use this ID to query for record details
Let’s Get Technical: Code Examples
Here’s a simplified example to illustrate the concept.
Sample Apex Class for Agent Action:
public class DealManagementController {
@InvocableMethod( label='Deal Check' )
public static List < Opportunity > checkDeal(
List < String > listRecordIds
) {
if (
listRecordIds != null &&
listRecordIds.size() > 0
) {
System.debug(
'Record Id::' +
listRecordIds.get( 0 )
);
return [
SELECT Id, Name, Amount,
StageName, Type, CloseDate
FROM Opportunity
WHERE Id =: listRecordIds.get( 0 )
];
} else {
return null;
}
}
}
Agent Action:

Agent Topic:

Instruction:
Pass the Context Variable currentRecordId to the Deal Check Action
Output:
