Short answer: Use a Named Credential plus an auth provider for secure authentication, send batched HTTP requests from a Queueable Apex job for callouts, and expose an @InvocableMethod for Flow and a Apex @AuraEnabled method for LWC. This pattern keeps you within governor limits and supports retries and logging for Agentforce interactions.
Agentforce is a Salesforce product for conversational and agent assistance workflows that pairs with Einstein AI features. You integrate when you need programmatic control over conversations, to push or pull context, or to call Agentforce actions from Salesforce automations.
Integrate Agentforce when you must: enrich a case with conversation context, surface recommendations in a Lightning page, or run automated routing from Apex or Flow.
Setup steps (OAuth-backed Named Credential):
Use Named Credentials so your code calls a stable name (callout:Agentforce_NC) and Salesforce manages token refresh.
Use a queueable batch approach: collect records in a trigger or bulk process and enqueue a single Queueable job that performs the HTTP callouts in bulk. That avoids callouts inside triggers and spreads network I/O outside the DML transaction.
Apex Queueable pattern (bulk-safe):
public with sharing class AgentforceCalloutQueueable implements Queueable, Database.AllowsCallouts {private List<Id> caseIds;public AgentforceCalloutQueueable(List<Id> caseIds) {this.caseIds = caseIds;}public void execute(QueueableContext ctx) {// Bulk query outside loopsList<Case> cases = [SELECT Id, Subject, Description FROM Case WHERE Id IN :caseIds];// Build bulk payloadList<Map<String, Object>> payload = new List<Map<String, Object>>();for (Case c : cases) {payload.add(new Map<String, Object>{'caseId' => c.Id, 'subject' => c.Subject, 'body' => c.Description});}HttpRequest req = new HttpRequest();req.setEndpoint('callout:Agentforce_NC/v1/conversations/batch');req.setMethod('POST');req.setHeader('Content-Type', 'application/json');req.setBody(JSON.serialize(payload));Http http = new Http();HttpResponse res = http.send(req);if (res.getStatusCode() >= 200 && res.getStatusCode() < 300) {// parse response and write lightweight results (avoid heavy DML)// Example: log statuses to a custom object or Platform Event} else {// Use Platform Events or custom error object for retry/alert}}}
Trigger that enqueues the job (bulk-safe):
trigger CaseAfterInsert on Case (after insert) {List<Id> ids = new List<Id>();for (Case c : Trigger.new) ids.add(c.Id);System.enqueueJob(new AgentforceCalloutQueueable(ids));}
Flow: create an Apex invocable that enqueues the same Queueable class or performs a single HTTP callout. Then call that from your Flow using an Action element.
Flow element example: Get Records → Action (Apex: AgentforceInvocable.send) → Decision → Update Records. This keeps the flow user-facing steps fast while the actual network call runs asynchronously.
Invocable Apex example (for Flow):
public with sharing class AgentforceInvocable {public class Request { @InvocableVariable public Id recordId; }@InvocableMethod(label='Send to Agentforce')public static void send(List<Request> requests) {List<Id> ids = new List<Id>();for (Request r : requests) ids.add(r.recordId);System.enqueueJob(new AgentforceCalloutQueueable(ids));}}
LWC: call an @AuraEnabled Apex method that enqueues the queueable job. Keep LWC logic limited to UI state; avoid parsing large responses in the client.
Example LWC controller call (JS):
// Apex importimport sendToAgentforce from '@salesforce/apex/AgentforceInvocable.send';// callsendToAgentforce({ requests: [{ recordId: this.recordId }] }).then(() => { /* success toast */ }).catch(error => { /* show error */ });
Patterns:
Limits and considerations:
Compare options:
| Pattern | Use when | Governor concerns |
|---|---|---|
| Synchronous callout | small UI fetch, immediate response | counts against request timeouts, 100 callouts/txn |
| Queueable callout | bulk sends, retries, logs | 50 jobs/txn, allows callouts outside trigger flow |
| Platform Event | high reliability, retries | separate transaction, replayable |
You need System Administrator or a profile/permission set with Manage Named Credentials and Manage Auth. Providers. Create them at Setup → Named Credentials and Setup → Auth. Providers.
Yes. Use an Apex @InvocableMethod that enqueues a Queueable job, then call that Apex action from your record-triggered flow (Get Records → Action → Update Records).
Capture failures to a custom object or Platform Event and process them with a scheduled job or a replayable subscriber. Avoid tight retry loops inside the same transaction.
Yes. Use Named Credentials and Custom Metadata to store environment-specific endpoints and switches. Update the Named Credential per sandbox or production environment.
Check the Salesforce Developer Docs and your org’s Agentforce documentation via Setup and the product’s developer guide: https://developer.salesforce.com/docs.
Linking notes: if you need background on building reports against Agentforce logs, see the Salesforce reports and dashboards guide here: [/the-ultimate-guide-to-salesforce-reports-and-dashboards-for-admins/]. For trigger best practices used here, review Salesforce trigger context variables explained: [/salesforce-trigger-context-variables-explained/].
Run the Queueable in a sandbox and validate results in debug logs and a small batch of records before scaling to production.
Quick Links
Legal Stuff
