name: salesforce-agentforce
description: Salesforce Agentforce and Einstein AI integration patterns. Use when building AI agents that interact with Salesforce CRM via Agentforce skills, MuleSoft connectors, Data Cloud, or the Einstein Trust Layer.
tags: [salesforce, crm, agentforce, einstein]
Salesforce Agentforce Integration
Build AI agents that connect to Salesforce CRM using Agentforce skills, the Einstein Trust Layer, Data Cloud grounding, and MuleSoft connectors.
When to Use
- Querying or updating Salesforce records (Accounts, Contacts, Opportunities, Cases) from AI agents
- Building autonomous sales/service agents powered by Claude, GPT-4, or Gemini via Salesforce's multi-model Trust Layer
- Grounding AI responses in Salesforce Data Cloud customer profiles
- Orchestrating cross-system workflows via MuleSoft (Salesforce + SAP, ServiceNow, Oracle)
Agentforce Pre-Built Agent Types
| Agent |
Capabilities |
| Service Agent |
Autonomous customer service, case resolution, KB search, escalation |
| SDR Agent |
Lead qualification, meeting scheduling, follow-up emails, prospect research |
| Sales Coach |
Role-play practice, deal strategy, objection handling |
| Marketing Agent |
Campaign creation, audience segmentation, content generation |
| Commerce Agent |
Product recommendations, guided shopping, order management |
| Analytics Agent |
Natural language data queries, dashboard generation |
Patterns
1. Salesforce REST API (SOQL Queries)
import requests
class SalesforceClient:
def __init__(self, instance_url: str, access_token: str):
self.base_url = f"{instance_url}/services/data/v60.0"
self.headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
}
def query(self, soql: str) -> list[dict]:
"""Execute a SOQL query."""
response = requests.get(
f"{self.base_url}/query",
params={"q": soql},
headers=self.headers,
)
response.raise_for_status()
return response.json()["records"]
def create_record(self, sobject: str, data: dict) -> str:
"""Create a Salesforce record."""
response = requests.post(
f"{self.base_url}/sobjects/{sobject}",
json=data,
headers=self.headers,
)
response.raise_for_status()
return response.json()["id"]
def update_record(self, sobject: str, record_id: str, data: dict) -> None:
"""Update a Salesforce record."""
response = requests.patch(
f"{self.base_url}/sobjects/{sobject}/{record_id}",
json=data,
headers=self.headers,
)
response.raise_for_status()
# Agent tool functions
def search_accounts(name: str) -> list[dict]:
sf = get_salesforce_client()
return sf.query(f"SELECT Id, Name, Industry, AnnualRevenue FROM Account WHERE Name LIKE '%{name}%' LIMIT 10")
def get_open_opportunities(account_id: str) -> list[dict]:
sf = get_salesforce_client()
return sf.query(f"SELECT Id, Name, Amount, StageName, CloseDate FROM Opportunity WHERE AccountId = '{account_id}' AND IsClosed = false ORDER BY Amount DESC")
def create_case(account_id: str, subject: str, description: str, priority: str = "Medium") -> str:
sf = get_salesforce_client()
return sf.create_record("Case", {
"AccountId": account_id,
"Subject": subject,
"Description": description,
"Priority": priority,
"Origin": "AI Agent",
})
2. OAuth 2.0 Authentication (JWT Bearer Flow)
import jwt
import time
import requests
def get_salesforce_token(
client_id: str,
private_key: str,
username: str,
login_url: str = "https://login.salesforce.com",
) -> dict:
"""Authenticate using JWT Bearer flow (server-to-server)."""
claim = {
"iss": client_id,
"sub": username,
"aud": login_url,
"exp": int(time.time()) + 300,
}
assertion = jwt.encode(claim, private_key, algorithm="RS256")
response = requests.post(
f"{login_url}/services/oauth2/token",
data={
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion": assertion,
},
)
response.raise_for_status()
return response.json() # {"access_token": "...", "instance_url": "..."}
3. MuleSoft Connector Orchestration
AI Agent Request
--> MuleSoft Anypoint Platform
--> Pre-built Connector (SAP, Oracle, ServiceNow)
--> Transform (DataWeave)
--> Return structured result
--> AI Agent synthesizes response
MuleSoft provides 1,000+ pre-built connectors. Key enterprise connectors:
- SAP (S/4HANA, ECC, Ariba, SuccessFactors)
- Oracle (ERP Cloud, HCM, Database)
- ServiceNow (ITSM, CSM, HR)
- Workday (HCM, Finance)
4. Einstein Trust Layer (Multi-Model)
Salesforce's Trust Layer supports multiple LLM backends:
| Provider |
Models |
Access Path |
| OpenAI |
GPT-4, GPT-4o |
Direct integration |
| Anthropic |
Claude 3, Claude 3.5 |
Via AWS Bedrock |
| Google |
Gemini 1.5 |
Via model gateway |
| Salesforce |
xGen, CodeGen |
Native |
| Custom |
Any REST endpoint |
BYOM (Bring Your Own Model) |
Trust Layer capabilities:
- PII masking before sending to LLMs
- Response grounding in Salesforce data
- Audit trail of all AI interactions
- Zero data retention by LLM providers
- Toxicity and bias detection
Anti-Patterns
- Hardcoding Salesforce credentials -- use OAuth JWT flow or Named Credentials
- Querying all fields with
SELECT * -- SOQL requires explicit field selection
- Bypassing the Trust Layer for direct LLM calls -- loses PII protection and audit trail
- Building custom integrations when MuleSoft connectors exist -- leverage existing connectors
- Ignoring governor limits -- Salesforce has API call limits per 24-hour period
References
1---2name: salesforce-agentforce-23description: <!-- AUTO-GENERATED by export-skills.py — DO NOT EDIT -->4---5<!-- AUTO-GENERATED by export-skills.py — DO NOT EDIT -->6---7name: salesforce-agentforce8description: Salesforce Agentforce and Einstein AI integration patterns. Use when building AI agents that interact with Salesforce CRM via Agentforce skills, MuleSoft connectors, Data Cloud, or the Einstein Trust Layer.9tags: [salesforce, crm, agentforce, einstein]10---1112# Salesforce Agentforce Integration1314Build AI agents that connect to Salesforce CRM using Agentforce skills, the Einstein Trust Layer, Data Cloud grounding, and MuleSoft connectors.1516## When to Use1718- Querying or updating Salesforce records (Accounts, Contacts, Opportunities, Cases) from AI agents19- Building autonomous sales/service agents powered by Claude, GPT-4, or Gemini via Salesforce's multi-model Trust Layer20- Grounding AI responses in Salesforce Data Cloud customer profiles21- Orchestrating cross-system workflows via MuleSoft (Salesforce + SAP, ServiceNow, Oracle)2223## Agentforce Pre-Built Agent Types2425| Agent | Capabilities |26|---|---|27| **Service Agent** | Autonomous customer service, case resolution, KB search, escalation |28| **SDR Agent** | Lead qualification, meeting scheduling, follow-up emails, prospect research |29| **Sales Coach** | Role-play practice, deal strategy, objection handling |30| **Marketing Agent** | Campaign creation, audience segmentation, content generation |31| **Commerce Agent** | Product recommendations, guided shopping, order management |32| **Analytics Agent** | Natural language data queries, dashboard generation |3334## Patterns3536### 1. Salesforce REST API (SOQL Queries)3738```python39import requests4041class SalesforceClient:42 def __init__(self, instance_url: str, access_token: str):43 self.base_url = f"{instance_url}/services/data/v60.0"44 self.headers = {45 "Authorization": f"Bearer {access_token}",46 "Content-Type": "application/json",47 }4849 def query(self, soql: str) -> list[dict]:50 """Execute a SOQL query."""51 response = requests.get(52 f"{self.base_url}/query",53 params={"q": soql},54 headers=self.headers,55 )56 response.raise_for_status()57 return response.json()["records"]5859 def create_record(self, sobject: str, data: dict) -> str:60 """Create a Salesforce record."""61 response = requests.post(62 f"{self.base_url}/sobjects/{sobject}",63 json=data,64 headers=self.headers,65 )66 response.raise_for_status()67 return response.json()["id"]6869 def update_record(self, sobject: str, record_id: str, data: dict) -> None:70 """Update a Salesforce record."""71 response = requests.patch(72 f"{self.base_url}/sobjects/{sobject}/{record_id}",73 json=data,74 headers=self.headers,75 )76 response.raise_for_status()7778# Agent tool functions79def search_accounts(name: str) -> list[dict]:80 sf = get_salesforce_client()81 return sf.query(f"SELECT Id, Name, Industry, AnnualRevenue FROM Account WHERE Name LIKE '%{name}%' LIMIT 10")8283def get_open_opportunities(account_id: str) -> list[dict]:84 sf = get_salesforce_client()85 return sf.query(f"SELECT Id, Name, Amount, StageName, CloseDate FROM Opportunity WHERE AccountId = '{account_id}' AND IsClosed = false ORDER BY Amount DESC")8687def create_case(account_id: str, subject: str, description: str, priority: str = "Medium") -> str:88 sf = get_salesforce_client()89 return sf.create_record("Case", {90 "AccountId": account_id,91 "Subject": subject,92 "Description": description,93 "Priority": priority,94 "Origin": "AI Agent",95 })96```9798### 2. OAuth 2.0 Authentication (JWT Bearer Flow)99100```python101import jwt102import time103import requests104105def get_salesforce_token(106 client_id: str,107 private_key: str,108 username: str,109 login_url: str = "https://login.salesforce.com",110) -> dict:111 """Authenticate using JWT Bearer flow (server-to-server)."""112 claim = {113 "iss": client_id,114 "sub": username,115 "aud": login_url,116 "exp": int(time.time()) + 300,117 }118 assertion = jwt.encode(claim, private_key, algorithm="RS256")119120 response = requests.post(121 f"{login_url}/services/oauth2/token",122 data={123 "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",124 "assertion": assertion,125 },126 )127 response.raise_for_status()128 return response.json() # {"access_token": "...", "instance_url": "..."}129```130131### 3. MuleSoft Connector Orchestration132133```134AI Agent Request135 --> MuleSoft Anypoint Platform136 --> Pre-built Connector (SAP, Oracle, ServiceNow)137 --> Transform (DataWeave)138 --> Return structured result139 --> AI Agent synthesizes response140```141142MuleSoft provides 1,000+ pre-built connectors. Key enterprise connectors:143- SAP (S/4HANA, ECC, Ariba, SuccessFactors)144- Oracle (ERP Cloud, HCM, Database)145- ServiceNow (ITSM, CSM, HR)146- Workday (HCM, Finance)147148### 4. Einstein Trust Layer (Multi-Model)149150Salesforce's Trust Layer supports multiple LLM backends:151152| Provider | Models | Access Path |153|---|---|---|154| OpenAI | GPT-4, GPT-4o | Direct integration |155| Anthropic | Claude 3, Claude 3.5 | Via AWS Bedrock |156| Google | Gemini 1.5 | Via model gateway |157| Salesforce | xGen, CodeGen | Native |158| Custom | Any REST endpoint | BYOM (Bring Your Own Model) |159160Trust Layer capabilities:161- PII masking before sending to LLMs162- Response grounding in Salesforce data163- Audit trail of all AI interactions164- Zero data retention by LLM providers165- Toxicity and bias detection166167## Anti-Patterns168169- Hardcoding Salesforce credentials -- use OAuth JWT flow or Named Credentials170- Querying all fields with `SELECT *` -- SOQL requires explicit field selection171- Bypassing the Trust Layer for direct LLM calls -- loses PII protection and audit trail172- Building custom integrations when MuleSoft connectors exist -- leverage existing connectors173- Ignoring governor limits -- Salesforce has API call limits per 24-hour period174175## References176177- [Salesforce Agentforce](https://www.salesforce.com/agentforce/)178- [Salesforce REST API](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/)179- [Einstein Trust Layer](https://www.salesforce.com/artificial-intelligence/trusted-ai/)180- [MuleSoft Connectors](https://www.mulesoft.com/exchange/)181- [Salesforce MCP Server](https://github.com/salesforce/mcp-server)182183<!-- Source: .faos/custom/skills/integrations/salesforce-agentforce/SKILL.md -->