🏠 Home 🔒 Record Sharing ⚙ Apex Triggers 🔍 SOQL 💻 LWC 🔗 Integration 🤖 Flows & Automation 🤖 Agentforce & AI 🎈 Agentforce Course — Free ☁ Data Cloud 🎓 DC Course — Free 💵 CPQ 🎯 100 Scenario Questions 🏆 150 Advanced Questions 📧 Marketing Cloud 🏗️ Company Wise 👥 About Us Start Learning Free →

Agentforce API Actions — External Services & OpenAPI 2026

📅  Agentforce
Agentforce Course Module 10: API Actions | sfinterviewpro.com
🌍 Agentforce Free Course — Module 10

API Actions
Connect Your Agent to External Systems

Call any external REST API from your Agentforce agent using External Services, Named Credentials & OpenAPI specs. Build the XYZ Company ERP integration live.

🔗 External Services 🔑 Named Credentials 📄 OpenAPI Spec 🎯 XYZ Company ERP ✅ Hands-On
Course Progress
Module 10 of 15 — 67% Complete
💡

What Are API Actions?

The bridge between your Agentforce agent and the outside world

🔗 Definition
API Actions allow your Agentforce agent to call external REST APIs in real time — fetching data from or pushing data to systems outside Salesforce, like ERPs, CRMs, databases, or any web service with a REST API.
🌟 How API Actions Flow
🤖 AgentUser asks question
👁 TopicClassifies intent
🔗 API ActionExternal Service call
🔑 Named CredentialSecure auth
🌎 External APIERP / Database
💡 Real World Example
User asks: “What is the current stock level of Product XYZ?”
Agent fires API Action → calls XYZ Company Business Central ERP → gets live stock data → responds to user with real-time inventory.
No human needed. No manual lookup. Zero latency.
⚖️

API Actions vs Apex Actions vs Flow Actions

Know when to use which

⚙️
Apex Actions
Complex Salesforce logic, aggregate queries, business rules, calculations

Internal — stays within Salesforce
🔗
API Actions
Call any external REST API — ERP, inventory, shipping, payments, weather

External — reaches outside Salesforce
🔄
Flow Actions
Declarative automation — create/update records, send emails, approval process

Declarative — no code needed
ScenarioBest Action TypeWhy
Get live inventory from Business Central🔗 API ActionExternal system call
Calculate pipeline summary from Opportunities⚙️ Apex ActionInternal SOQL + logic
Create follow-up Task for Account🔄 Flow ActionSimple record creation
Get weather forecast for customer location🔗 API ActionExternal REST API
Update Opportunity Stage to Closed Won🔄 Flow ActionDML, no external call
Send shipment tracking to customer🔗 API ActionExternal shipping API
🛠️

3 Ways to Create API Actions in Agentforce

Choose based on your use case

MethodHowBest ForSkill Level
External Services (OpenAPI)Register OpenAPI spec → auto-generates invocable actionsWell-documented APIs with OpenAPI/Swagger⭐ Intermediate
Apex @InvocableMethod with CalloutWrite Apex that calls HTTP + mark @InvocableMethodComplex APIs needing custom logic/parsing🔥 Advanced
Flow with HTTP Callout StepSalesforce Flow → HTTP Action elementSimple REST calls, no complex parsing✅ Beginner
✅ This Module Covers
Method 1: External Services (OpenAPI) — the official Agentforce-recommended approach. Register once, use everywhere. Auto-generates invocable actions from your API spec.
🚀

Step-by-Step: Build XYZ Company ERP API Action

Live hands-on setup in your Developer Org

📋 Step 1: Create the OpenAPI Specification

An OpenAPI spec describes your external API — endpoints, parameters, responses. Salesforce reads this to auto-generate invocable actions.

Save this as xyz_erp_api.json

{ "openapi": "3.0.0", "info": { "title": "XYZ Company ERP API", "version": "1.0.0", "description": "Business Central integration for XYZ Company" }, "servers": [ { "url": "https://api.xyz-erp.com/v1" } ], "paths": { "/inventory/{productCode}": { "get": { "operationId": "getInventoryLevel", "summary": "Get current inventory level for a product", "parameters": [ { "name": "productCode", "in": "path", "required": true, "schema": { "type": "string" }, "description": "Product code from Salesforce" } ], "responses": { "200": { "description": "Inventory data returned", "content": { "application/json": { "schema": { "type": "object", "properties": { "productCode": { "type": "string" }, "productName": { "type": "string" }, "quantityOnHand": { "type": "integer" }, "warehouseLocation": { "type": "string" }, "lastUpdated": { "type": "string" } } } } } } } } }, "/orders/customer/{accountId}": { "get": { "operationId": "getCustomerOrders", "summary": "Get recent orders for a customer account", "parameters": [ { "name": "accountId", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Order list returned", "content": { "application/json": { "schema": { "type": "object", "properties": { "orders": { "type": "array", "items": { "type": "object", "properties": { "orderId": { "type": "string" }, "orderDate": { "type": "string" }, "totalAmount": { "type": "number" }, "status": { "type": "string" } } } } } } } } } } } } } }
💡 Key Rules for OpenAPI Spec in Salesforce
  • operationId is mandatory — Salesforce uses this as the action name
  • OpenAPI 3.0.x only — Swagger 2.0 not supported in External Services v4+
  • Response schema must be defined — Salesforce needs to know output structure
  • Max spec size: 1MB — split large APIs into multiple External Services
🔑 Step 2: Set Up Named Credential

Named Credential securely stores the external API’s base URL and authentication. The External Service references it — no hardcoded URLs or credentials in code.

  • 1Setup → Quick Find: “Named Credentials” → New
  • 2Label: XYZ_ERP_API  |  Name: XYZ_ERP_API
  • 3URL: https://api.xyz-erp.com/v1
  • 4Authentication Protocol: OAuth 2.0 (or API Key based on your ERP)
  • 5For API Key auth: Authentication Protocol = No Authentication → add API key as Custom Header in External Service
  • 6Check “Allow Merge Fields in HTTP Header” and “Allow Merge Fields in HTTP Body”
  • 7Save ✅
// Named Credential configuration summary Label: XYZ_ERP_API Name: XYZ_ERP_API URL: https://api.xyz-erp.com/v1 Protocol: OAuth 2.0 (JWT Bearer recommended for server-to-server) // In Apex callout, referenced as: req.setEndpoint('callout:XYZ_ERP_API/inventory/' + productCode);
📄 Step 3: Register External Service

This is where Salesforce reads your OpenAPI spec and auto-generates invocable actions you can use in Agentforce, Flow, and Apex.

  • 1Setup → Quick Find: “External Services” → New External Service
  • 2Service Name: XYZ_ERP_Service
  • 3Named Credential: XYZ_ERP_API (from Step 2)
  • 4Service Schema: Select “Provide a complete schema inline” or “Enter a URL” if your API has a public spec URL
  • 5Paste the OpenAPI JSON from Step 1 into the schema editor
  • 6Click Save & Next → Salesforce validates the spec
  • 7Select which operations to register as actions:
       • ✅ getInventoryLevel
       • ✅ getCustomerOrders
  • 8Click Finish → External Service created! ✅
🎉 What Salesforce Auto-Creates
After saving External Service, Salesforce automatically generates:
Invocable Actions → usable in Flow, Agentforce, Apex
Input/Output classes → typed parameters matching your OpenAPI schema
• No manual Apex writing needed for the callout!
🤖 Step 4: Add API Action to Agentforce

Now connect your registered External Service as an action in the XYZ Sales Assistant agent.

  • 1Setup → Agents → XYZ Sales Assistant → Open in Agent Builder
  • 2Click your Topic (e.g., Account & Inventory Lookup)
  • 3Click “+ New Action”
  • 4Action Type: “External Service”
  • 5Select: XYZ_ERP_Service → select operation getInventoryLevel
  • 6Action Label: Get Product Inventory Level
    Description: “Retrieves the current stock level and warehouse location for a specific product code from XYZ Company ERP system.”
  • 7Map input: productCode → Agent collects from user conversation
  • 8Save ✅ → Repeat for getCustomerOrders
👉 Action Description Best Practices
The description is read by Einstein LLM to decide WHEN to trigger the action. Be specific:
❌ Bad: “Gets inventory”
✅ Good: “Retrieves real-time stock quantity and warehouse location for a product code. Use when user asks about availability, stock levels, or inventory of a specific product.”
👁 Step 5: Create a New Topic for ERP Queries
// Topic 4: ERP & Inventory Lookup Topic Name: ERP & Inventory Lookup Classification Description: "Handle queries about product inventory levels, stock availability, customer order history, and ERP data from Business Central. Triggered when user asks about stock, availability, orders placed, shipment status, or product quantities." Instructions (add to topic): 1. Always ask for product code if not provided in query 2. Call getInventoryLevel with the provided product code 3. Present quantityOnHand and warehouseLocation clearly 4. If quantity is below 100, add a low stock warning 5. For order queries, call getCustomerOrders with Account ID 6. Always mention the lastUpdated timestamp from ERP response 7. If API returns error, inform user politely and suggest contacting support Actions added to this Topic: ✓ Get Product Inventory Level (External Service: getInventoryLevel) ✓ Get Customer Orders (External Service: getCustomerOrders) ✓ Get Record Details (Standard Action - for Account lookup)
🎯

Live Test Conversations

What your agent does with the API Actions connected

🎯 Test 1 — Inventory Query
User: What is the current stock level of product SILI-001?
Agent: Here’s the current inventory for product SILI-001:

📦 Product: Silicone Rubber Sheet SILI-001
📊 Stock Level: 847 units
🏭 Warehouse: Mumbai Main Warehouse
🕑 Last Updated: 23 May 2026, 09:45 AM

✅ Stock is healthy. Is there anything else you’d like to know?
✅ Agent called getInventoryLevel(productCode=“SILI-001”) → ERP returned live data → Agent formatted and responded
🎯 Test 2 — Low Stock Warning
User: Check inventory for POLY-047
Agent: Inventory update for POLY-047:

📦 Product: Polymer Gasket POLY-047
📊 Stock Level: 43 units
🏭 Warehouse: Ahmedabad Storage B

⚠️ Low Stock Alert! Quantity is below 100 units. Consider placing a replenishment order soon to avoid stockouts.
✅ Agent applied instruction #4 (quantity < 100 = low stock warning). Business logic in Topic Instructions, not in code!
🎯 Test 3 — Customer Orders
User: Show me recent orders for ABC Pharma
Agent: Here are the recent orders for ABC Pharma:

1. 📋 Order #ERP-28947 — 18 May 2026 — ₹1,24,500 — Delivered
2. 📋 Order #ERP-28651 — 05 May 2026 — ₹87,200 — In Transit
3. 📋 Order #ERP-28102 — 22 Apr 2026 — ₹2,15,000 — Delivered

Total value: ₹4,26,700 across 3 recent orders. Would you like details on any specific order?
✅ Agent looked up ABC Pharma Account ID from Salesforce first, then called getCustomerOrders(accountId) on ERP
🛑

Error Handling for API Actions

What happens when the external API fails

🚨 Without Error Handling
If external API returns 500 or timeout → Agentforce shows a generic error to the user → Bad experience. Always add fault handling in your Topic Instructions.
// Topic Instructions — Error Handling section 8. If the ERP API returns an error or is unavailable: - Apologize politely: "I'm unable to fetch live ERP data right now." - Offer alternative: "You can check directly in Business Central." - Log the issue: Create a Platform Event for error monitoring - DO NOT show: technical error codes or stack traces to users 9. If product code is not found in ERP: - Ask user to verify the product code - Suggest searching by product name instead 10. For timeout errors (API takes >10 seconds): - Inform user of delay - Offer to send results via email when available
Error TypeAgent ResponseTechnical Action
API 404 (Not Found)“Product code not found in ERP”Ask for correct code
API 401 (Unauthorized)“ERP data temporarily unavailable”Check Named Credential token refresh
API 500 (Server Error)“ERP system is experiencing issues”Fire Platform Event for alert
Timeout“Taking longer than usual”Retry once, then fallback
Schema mismatch“Unexpected data format”Update OpenAPI spec
🎉

XYZ Sales Assistant: Full Capabilities After M10

What your agent can do now

✅ Salesforce Data (M7-M9)
  • ✓ Query Accounts + Contacts
  • ✓ Full Account + Opportunity profiles
  • ✓ Aggregate pipeline summary
  • ✓ Generate AI emails (Prompt Template)
  • ✓ Create follow-up Tasks (Flow)
  • ✓ Update Opportunity stages (Flow)
🔗 External ERP Data (M10 NEW!)
  • ✓ Live product inventory levels
  • ✓ Low stock alerts automatically
  • ✓ Customer order history from ERP
  • ✓ Real-time warehouse data
  • ✓ Extensible to any REST API
🌟 The Power of API Actions
Your agent is no longer limited to Salesforce data. It can reach into any external system with a REST API — ERP, shipping, payments, weather, HR systems, custom databases — and bring that data into your AI conversations in real time. This is what makes Agentforce enterprise-grade.
🎤

Interview Q&A — API Actions in Agentforce

Real questions asked in Agentforce interviews 2026

Q1
What is an External Service in Salesforce and how does it relate to Agentforce API Actions?
✅ Answer
External Services is a Salesforce feature that reads an OpenAPI specification of a REST API and auto-generates invocable actions — no manual Apex callout code needed. These auto-generated actions are directly usable as API Actions in Agentforce, Flows, and Process Builders.
🎤 One-Line Answer
"External Services reads your OpenAPI spec and auto-generates invocable actions. Agentforce uses these as API Actions to call external systems — no callout code needed."
Q2
When would you use an API Action vs an Apex Action in Agentforce?
✅ Answer
API Action when calling external systems (ERP, shipping, external database) via REST — use External Services for well-documented APIs. Apex Action when logic is internal to Salesforce (complex SOQL, business calculations, DML) or when the external API needs complex custom logic/parsing that OpenAPI can’t handle.
ChooseWhen
API ActionExternal REST API with clear OpenAPI spec, simple request/response
Apex ActionInternal Salesforce logic, complex parsing, multi-step business rules
Flow ActionSimple record operations, declarative automation, no external calls
🎤 One-Line Answer
"API Action for external REST calls via External Services. Apex Action for internal Salesforce logic or complex API parsing. Flow Action for declarative record operations."
Q3
What is the role of Named Credentials in Agentforce API Actions?
✅ Answer
Named Credentials store the external API’s endpoint URL and authentication (OAuth, API key, certificate) encrypted in Salesforce. External Services reference Named Credentials so no credentials are hardcoded in specs or code. Auto-refreshes OAuth tokens, passes credentials securely in every API call.
🎤 One-Line Answer
"Named Credentials: encrypted endpoint + auth for external APIs. External Services reference them — zero hardcoded credentials, auto OAuth refresh, secure for every API call."
Q4
In XYZ Company, your agent needs to check live inventory from Business Central ERP. What is the step-by-step approach?
✅ Answer
1) Create OpenAPI spec for Business Central inventory endpoint. 2) Set up Named Credential with BC API URL + OAuth. 3) Register External Service pointing to Named Credential + spec. 4) Add generated action to Agentforce Topic. 5) Write Topic Instructions describing when to trigger and how to handle response. 6) Test in Agent Builder preview.
🎤 One-Line Answer
"OpenAPI spec → Named Credential → External Service → Agentforce Action → Topic Instructions. Six steps, no custom callout code, live ERP data in your agent."
Q5
What are the limitations of External Services in Salesforce?
✅ Answer
Key limitations: OpenAPI 3.0.x only (no Swagger 2.0), max spec size 1MB, complex nested schemas may not map cleanly, no streaming support, can’t handle file uploads/binary responses, synchronous only (no async callbacks), limited to standard HTTP methods.
  • 🔴OpenAPI 3.0.x only — Swagger 2.0 not supported
  • 🔴Max spec size: 1MB — split large APIs
  • 🔴No binary/file response support — JSON/XML only
  • 🔴Synchronous only — long-running APIs need different approach
  • 🔴Complex deeply nested schemas may need simplification
🎤 One-Line Answer
"External Services: OpenAPI 3.0 only, 1MB max, no binary/streaming, synchronous. For complex APIs, use Apex @InvocableMethod with callout instead."
📋

Module 10 Summary

What you learned and built

📚 Key Concepts
  • API Actions vs Apex vs Flow Actions
  • External Services + OpenAPI spec
  • Named Credentials for secure auth
  • Topic Instructions for API error handling
  • Action description best practices
🛠️ What You Built
  • XYZ ERP OpenAPI spec (2 endpoints)
  • Named Credential: XYZ_ERP_API
  • External Service: XYZ_ERP_Service
  • Topic 4: ERP & Inventory Lookup
  • 2 API Actions connected to agent

🌍 Free Agentforce Course

15 modules, hands-on, real XYZ Company project. No signup. No paywall. Built by a Salesforce developer for Salesforce professionals.

Browse All Topics →