Before You Begin
Before setting up the Salesforce integration with Agent.ai, ensure you have: Tested Your Agent with cURL: Verify your Agent.ai webhook is functional by testing it with cURL first. This confirms the endpoint is working and helps you understand the expected request/response format:- API Access in Salesforce: Ensure the Salesforce users who will be configuring and using this integration have:
- “API Enabled” permission
- “Modify All Data” or appropriate object-level permissions
- Access to create and modify Flows
- Permission to create Named Credentials
- Required Information:
- Your complete Agent.ai webhook URL
- The expected request payload structure
- The response format from your agent
- Salesforce fields you want to use for input/output
- Salesforce Edition: Confirm you’re using a Salesforce edition that supports Named Credentials and Flows (Enterprise, Unlimited, Developer, or Performance).
Creating Credentials
1. Create External Credentials
- Navigate to Setup → Named Credentials → External Credentials (Tab) → New
- Fill in the required fields (remember: Name must NOT contain spaces)
- Select No Authentication from the dropdown
- Save your settings
2. Create Named Credentials
- Navigate to Setup → Named Credentials → Named Credentials (Tab) → New
- Complete the form with:
- Label: A descriptive name (e.g., “AgentAI Named Credential”)
- Name: Same as label without spaces
- URL: Your Agent.ai endpoint (e.g., “https://api-lr.agent.ai”)
- Enable “Enabled for Callouts”
- Select your External Credential from the dropdown
- Check “Generate Authorization Header”
- Set Outbound Network Connection to “—None—”
- Save your settings
3. Create Principal for Named Credentials
- Navigate to Setup → Named Credentials → “AgentAI External Credential” → Principals → New
- Complete the form:
- Parameter Name: A descriptive name
- Sequence Number: 1
- Identity Type: “Named Principal”
- Save your settings
4. Create a Permission Set for External Credentials
- Navigate to Setup → Permission Sets → New
- Enter permission set details:
- Label: “AgentAI External Credentials Permissions”
- API Name: Should auto-populate
- Save your settings
5. Assign Permissions
- Navigate to Setup → Permission Sets → “AgentAI External Credentials Permissions” → Manage Assignments
- Click Add Assignment
- Select users who need access
- Click Next (no expiration date needed)
- Click Assign
6. Manage Permissions in Permission Set
- Navigate to Setup → Permission Sets → “AgentAI External Credentials Permissions” → External Credential Principal Access
- Click Edit
- Enable the Credential Principal
- Save your settings
- Verify your configuration
Creating The Flow
1. Create Record Triggered Flow
- Navigate to Setup → Flows → New Flow
- Select Record Triggered Flow
- Choose When A Record Is Created
- Set to optimize for “Action and Related Records”
- Check “Include a Run Asynchronously path to access an external system after the original transaction for the triggering record is successfully committed”
2. Create HTTP Callout Action
- Click Add Element
- Select Action
- Find and select Create HTTP Callout (scroll to the bottom of the list)
3. Create External Service
- Give your service a name (alphanumeric values only) Note: Use version names if creating multiple services
- Select your Named Credential from the dropdown
- Save your settings
4. Create Invokable Action
- Set Method to POST
- Enter URL Path to your Agent webhook endpoint
- Example: /v1/agent/kkmiv48izo6wo7fk/webhook/b45b7a8e
- For Sample JSON Request, copy from your webhook example:
- Example:
{"input_name":"REPLACE_ME"}
- Example:
- Ignore any error that appears
- Click Review
- Confirm data structure is detected (input_name as String)
- Click Connect for Schema
- Click Connect
- Review return types match what your Agent returns
- Name the Action for your external service
6. Assign Body Payload Parameters
- Click Assign → Set Variable Values
- Select data to pass to agent:
- Variable: agentRequestBody > input_name
- Operator: Equals
- Value: Choose your field (e.g., Triggering Lead > First Name)
- Save your settings
7. Save and Refresh The Page
- Save your flow to update the UI with new values
8. Set Up Response Handling
- Select the Flow Action → Show Advanced Options → Store Output Values
- For 2XX responses, create a new resource
- For Default Exception, create a new resource (Text type)
- For Response Code, create a new resource (Number, 0 decimal places)
- Save to finalize resource names
9. Assign Values from API Call to Objects
- After the HTTP Request Action, create an Assignment
- Update the triggering record:
- Field: The field you want to update (e.g., Greeting_Phrase__c)
- Value: responseBodyOut2XX > response
- Note: responseBodyOut2XX contains all output objects from your Agent
10. Test Your Flow
- Save your flow
- Click Debug
- Select Run Asynchronously
- Select a record to test with
- Run the flow and verify the results
Debug Checklist
Use this checklist to troubleshoot if your Agent.ai integration isn’t working properly:- External Credentials: Verify name contains no spaces and “No Authentication” is selected
- Named Credentials: Confirm URL is correct and “Enabled for Callouts” is checked
- Principal: Check that Principal is created with correct sequence number
- Permission Set: Ensure External Credential Principal is enabled
- User Assignments: Confirm relevant users have the permission set assigned
- Flow Trigger: Verify flow is set to trigger on the correct object and event
- HTTP Callout: Check that the webhook URL path is correct
- Request Body: Confirm input parameters match what your Agent expects (e.g., “input_name”)
- Response Handling: Ensure output variables are correctly mapped
- Field Updates: Verify targeted fields exist and are accessible for updates
- Asynchronous Execution: Confirm “Include to Run Asynchronously” is checked
- External Service: Check Named Credential is properly selected in External Service
- Flow Activation: Make sure the flow is activated after testing
- Agent Webhook: Verify your Agent.ai webhook endpoint is active and responding
- SFDC Logs: Review debug logs for any callout errors