Sub topic 3
Choosing and Limiting Agentforce Actions
Assume you know Salesforce objects, permission sets, sharing, and basic Apex or Flow. An action is an operation an Agentforce agent can invoke, such as querying an order or updating a case. Give an agent only the actions required for its job.
Choosing and limiting actions
For each action, define:
- The records it may access.
- The fields it may read or change.
- The inputs it accepts.
- The outcomes it can produce.
- The conditions that require escalation.
Prefer read-only actions when the agent does not need to change data. Validate inputs, limit returned records, and avoid actions that combine unrelated business operations. Instructions can tell the agent when to use an action, but code and Salesforce permissions must enforce the limit.
public with sharing class OrderStatusAction {
public class Request {
@InvocableVariable(required=true)
public String orderNumber;
}
public class Result {
@InvocableVariable
public String status;
}
@InvocableMethod(label='Get Order Status')
public static List<Result> getStatus(List<Request> requests) {
Set<String> numbers = new Set<String>();
for (Request request : requests) {
numbers.add(request.orderNumber);
}
Map<String, String> statuses = new Map<String, String>();
for (Order orderRecord : [
SELECT OrderNumber, Status
FROM Order
WHERE OrderNumber IN :numbers
WITH USER_MODE
]) {
statuses.put(orderRecord.OrderNumber, orderRecord.Status);
}
List<Result> results = new List<Result>();
for (Request request : requests) {
Result result = new Result();
result.status = statuses.get(request.orderNumber);
results.add(result);
}
return results;
}
}Enforcing permissions inside Apex and Flow actions
with sharing applies record-sharing rules to Apex. WITH USER_MODE also enforces the running user's object permissions and field-level security for the query. Without these controls, system-context code may expose records that the agent user should not see.
Flow actions should use a flow context and connected system settings that respect user permissions. Do not assume that an instruction prevents unauthorized access. Test the action with users who have different permission sets.
What the Einstein Trust Layer adds
The Einstein Trust Layer provides controls around model requests and responses. Depending on the configured feature, it can ground responses in Salesforce data, help protect sensitive data through masking, and support auditability. It does not replace object permissions, sharing, field-level security, action validation, or careful instructions.
Handing off to a human
Define explicit handoff conditions. Examples include refund requests, account changes, unavailable records, suspected fraud, or unclear identity. The agent should explain that it is transferring the conversation and avoid promising an outcome it cannot authorize.
Testing guardrails and reviewing activity
Test normal, unauthorized, ambiguous, and adversarial requests. Confirm that the agent cannot retrieve another customer's data, perform an unapproved change, or bypass a failed action. Review conversation logs, action invocations, errors, and handoffs. Repeat tests after changing permissions, topics, instructions, or actions.
Exercise
Why should an Apex action use both with sharing and WITH USER_MODE?
Show answer
with sharing enforces record-sharing rules, while WITH USER_MODE enforces the running user's object and field permissions for the query.