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.
Platform Note: This skill was designed for multi-agent execution. In Codex, treat sub-agent instructions as sequential steps to complete thoroughly within a single agent context.
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-agentforce3description: <!-- 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.9---1011> **Platform Note:** This skill was designed for multi-agent execution. In Codex, treat sub-agent instructions as sequential steps to complete thoroughly within a single agent context.1213# Salesforce Agentforce Integration1415Build AI agents that connect to Salesforce CRM using Agentforce skills, the Einstein Trust Layer, Data Cloud grounding, and MuleSoft connectors.1617## When to Use1819- Querying or updating Salesforce records (Accounts, Contacts, Opportunities, Cases) from AI agents20- Building autonomous sales/service agents powered by Claude, GPT-4, or Gemini via Salesforce's multi-model Trust Layer21- Grounding AI responses in Salesforce Data Cloud customer profiles22- Orchestrating cross-system workflows via MuleSoft (Salesforce + SAP, ServiceNow, Oracle)2324## Agentforce Pre-Built Agent Types2526| Agent | Capabilities |27|---|---|28| **Service Agent** | Autonomous customer service, case resolution, KB search, escalation |29| **SDR Agent** | Lead qualification, meeting scheduling, follow-up emails, prospect research |30| **Sales Coach** | Role-play practice, deal strategy, objection handling |31| **Marketing Agent** | Campaign creation, audience segmentation, content generation |32| **Commerce Agent** | Product recommendations, guided shopping, order management |33| **Analytics Agent** | Natural language data queries, dashboard generation |3435## Patterns3637### 1. Salesforce REST API (SOQL Queries)3839```python40import requests4142class SalesforceClient:43 def __init__(self, instance_url: str, access_token: str):44 self.base_url = f"{instance_url}/services/data/v60.0"45 self.headers = {46 "Authorization": f"Bearer {access_token}",47 "Content-Type": "application/json",48 }4950 def query(self, soql: str) -> list[dict]:51 """Execute a SOQL query."""52 response = requests.get(53 f"{self.base_url}/query",54 params={"q": soql},55 headers=self.headers,56 )57 response.raise_for_status()58 return response.json()["records"]5960 def create_record(self, sobject: str, data: dict) -> str:61 """Create a Salesforce record."""62 response = requests.post(63 f"{self.base_url}/sobjects/{sobject}",64 json=data,65 headers=self.headers,66 )67 response.raise_for_status()68 return response.json()["id"]6970 def update_record(self, sobject: str, record_id: str, data: dict) -> None:71 """Update a Salesforce record."""72 response = requests.patch(73 f"{self.base_url}/sobjects/{sobject}/{record_id}",74 json=data,75 headers=self.headers,76 )77 response.raise_for_status()7879# Agent tool functions80def search_accounts(name: str) -> list[dict]:81 sf = get_salesforce_client()82 return sf.query(f"SELECT Id, Name, Industry, AnnualRevenue FROM Account WHERE Name LIKE '%{name}%' LIMIT 10")8384def get_open_opportunities(account_id: str) -> list[dict]:85 sf = get_salesforce_client()86 return sf.query(f"SELECT Id, Name, Amount, StageName, CloseDate FROM Opportunity WHERE AccountId = '{account_id}' AND IsClosed = false ORDER BY Amount DESC")8788def create_case(account_id: str, subject: str, description: str, priority: str = "Medium") -> str:89 sf = get_salesforce_client()90 return sf.create_record("Case", {91 "AccountId": account_id,92 "Subject": subject,93 "Description": description,94 "Priority": priority,95 "Origin": "AI Agent",96 })97```9899### 2. OAuth 2.0 Authentication (JWT Bearer Flow)100101```python102import jwt103import time104import requests105106def get_salesforce_token(107 client_id: str,108 private_key: str,109 username: str,110 login_url: str = "https://login.salesforce.com",111) -> dict:112 """Authenticate using JWT Bearer flow (server-to-server)."""113 claim = {114 "iss": client_id,115 "sub": username,116 "aud": login_url,117 "exp": int(time.time()) + 300,118 }119 assertion = jwt.encode(claim, private_key, algorithm="RS256")120121 response = requests.post(122 f"{login_url}/services/oauth2/token",123 data={124 "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",125 "assertion": assertion,126 },127 )128 response.raise_for_status()129 return response.json() # {"access_token": "...", "instance_url": "..."}130```131132### 3. MuleSoft Connector Orchestration133134```135AI Agent Request136 --> MuleSoft Anypoint Platform137 --> Pre-built Connector (SAP, Oracle, ServiceNow)138 --> Transform (DataWeave)139 --> Return structured result140 --> AI Agent synthesizes response141```142143MuleSoft provides 1,000+ pre-built connectors. Key enterprise connectors:144- SAP (S/4HANA, ECC, Ariba, SuccessFactors)145- Oracle (ERP Cloud, HCM, Database)146- ServiceNow (ITSM, CSM, HR)147- Workday (HCM, Finance)148149### 4. Einstein Trust Layer (Multi-Model)150151Salesforce's Trust Layer supports multiple LLM backends:152153| Provider | Models | Access Path |154|---|---|---|155| OpenAI | GPT-4, GPT-4o | Direct integration |156| Anthropic | Claude 3, Claude 3.5 | Via AWS Bedrock |157| Google | Gemini 1.5 | Via model gateway |158| Salesforce | xGen, CodeGen | Native |159| Custom | Any REST endpoint | BYOM (Bring Your Own Model) |160161Trust Layer capabilities:162- PII masking before sending to LLMs163- Response grounding in Salesforce data164- Audit trail of all AI interactions165- Zero data retention by LLM providers166- Toxicity and bias detection167168## Anti-Patterns169170- Hardcoding Salesforce credentials -- use OAuth JWT flow or Named Credentials171- Querying all fields with `SELECT *` -- SOQL requires explicit field selection172- Bypassing the Trust Layer for direct LLM calls -- loses PII protection and audit trail173- Building custom integrations when MuleSoft connectors exist -- leverage existing connectors174- Ignoring governor limits -- Salesforce has API call limits per 24-hour period175176## References177178- [Salesforce Agentforce](https://www.salesforce.com/agentforce/)179- [Salesforce REST API](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/)180- [Einstein Trust Layer](https://www.salesforce.com/artificial-intelligence/trusted-ai/)181- [MuleSoft Connectors](https://www.mulesoft.com/exchange/)182- [Salesforce MCP Server](https://github.com/salesforce/mcp-server)183184<!-- Source: .faos/custom/skills/integrations/salesforce-agentforce/SKILL.md -->