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]
Platform Note: This skill was designed for multi-agent execution. Perplexity Computer handles orchestration automatically — treat sub-agent instructions as sequential steps to complete thoroughly.
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-33description: <!-- 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> **Platform Note:** This skill was designed for multi-agent execution. Perplexity Computer handles orchestration automatically — treat sub-agent instructions as sequential steps to complete thoroughly.1314# Salesforce Agentforce Integration1516Build AI agents that connect to Salesforce CRM using Agentforce skills, the Einstein Trust Layer, Data Cloud grounding, and MuleSoft connectors.1718## When to Use1920- Querying or updating Salesforce records (Accounts, Contacts, Opportunities, Cases) from AI agents21- Building autonomous sales/service agents powered by Claude, GPT-4, or Gemini via Salesforce's multi-model Trust Layer22- Grounding AI responses in Salesforce Data Cloud customer profiles23- Orchestrating cross-system workflows via MuleSoft (Salesforce + SAP, ServiceNow, Oracle)2425## Agentforce Pre-Built Agent Types2627| Agent | Capabilities |28|---|---|29| **Service Agent** | Autonomous customer service, case resolution, KB search, escalation |30| **SDR Agent** | Lead qualification, meeting scheduling, follow-up emails, prospect research |31| **Sales Coach** | Role-play practice, deal strategy, objection handling |32| **Marketing Agent** | Campaign creation, audience segmentation, content generation |33| **Commerce Agent** | Product recommendations, guided shopping, order management |34| **Analytics Agent** | Natural language data queries, dashboard generation |3536## Patterns3738### 1. Salesforce REST API (SOQL Queries)3940```python41import requests4243class SalesforceClient:44 def __init__(self, instance_url: str, access_token: str):45 self.base_url = f"{instance_url}/services/data/v60.0"46 self.headers = {47 "Authorization": f"Bearer {access_token}",48 "Content-Type": "application/json",49 }5051 def query(self, soql: str) -> list[dict]:52 """Execute a SOQL query."""53 response = requests.get(54 f"{self.base_url}/query",55 params={"q": soql},56 headers=self.headers,57 )58 response.raise_for_status()59 return response.json()["records"]6061 def create_record(self, sobject: str, data: dict) -> str:62 """Create a Salesforce record."""63 response = requests.post(64 f"{self.base_url}/sobjects/{sobject}",65 json=data,66 headers=self.headers,67 )68 response.raise_for_status()69 return response.json()["id"]7071 def update_record(self, sobject: str, record_id: str, data: dict) -> None:72 """Update a Salesforce record."""73 response = requests.patch(74 f"{self.base_url}/sobjects/{sobject}/{record_id}",75 json=data,76 headers=self.headers,77 )78 response.raise_for_status()7980# Agent tool functions81def search_accounts(name: str) -> list[dict]:82 sf = get_salesforce_client()83 return sf.query(f"SELECT Id, Name, Industry, AnnualRevenue FROM Account WHERE Name LIKE '%{name}%' LIMIT 10")8485def get_open_opportunities(account_id: str) -> list[dict]:86 sf = get_salesforce_client()87 return sf.query(f"SELECT Id, Name, Amount, StageName, CloseDate FROM Opportunity WHERE AccountId = '{account_id}' AND IsClosed = false ORDER BY Amount DESC")8889def create_case(account_id: str, subject: str, description: str, priority: str = "Medium") -> str:90 sf = get_salesforce_client()91 return sf.create_record("Case", {92 "AccountId": account_id,93 "Subject": subject,94 "Description": description,95 "Priority": priority,96 "Origin": "AI Agent",97 })98```99100### 2. OAuth 2.0 Authentication (JWT Bearer Flow)101102```python103import jwt104import time105import requests106107def get_salesforce_token(108 client_id: str,109 private_key: str,110 username: str,111 login_url: str = "https://login.salesforce.com",112) -> dict:113 """Authenticate using JWT Bearer flow (server-to-server)."""114 claim = {115 "iss": client_id,116 "sub": username,117 "aud": login_url,118 "exp": int(time.time()) + 300,119 }120 assertion = jwt.encode(claim, private_key, algorithm="RS256")121122 response = requests.post(123 f"{login_url}/services/oauth2/token",124 data={125 "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",126 "assertion": assertion,127 },128 )129 response.raise_for_status()130 return response.json() # {"access_token": "...", "instance_url": "..."}131```132133### 3. MuleSoft Connector Orchestration134135```136AI Agent Request137 --> MuleSoft Anypoint Platform138 --> Pre-built Connector (SAP, Oracle, ServiceNow)139 --> Transform (DataWeave)140 --> Return structured result141 --> AI Agent synthesizes response142```143144MuleSoft provides 1,000+ pre-built connectors. Key enterprise connectors:145- SAP (S/4HANA, ECC, Ariba, SuccessFactors)146- Oracle (ERP Cloud, HCM, Database)147- ServiceNow (ITSM, CSM, HR)148- Workday (HCM, Finance)149150### 4. Einstein Trust Layer (Multi-Model)151152Salesforce's Trust Layer supports multiple LLM backends:153154| Provider | Models | Access Path |155|---|---|---|156| OpenAI | GPT-4, GPT-4o | Direct integration |157| Anthropic | Claude 3, Claude 3.5 | Via AWS Bedrock |158| Google | Gemini 1.5 | Via model gateway |159| Salesforce | xGen, CodeGen | Native |160| Custom | Any REST endpoint | BYOM (Bring Your Own Model) |161162Trust Layer capabilities:163- PII masking before sending to LLMs164- Response grounding in Salesforce data165- Audit trail of all AI interactions166- Zero data retention by LLM providers167- Toxicity and bias detection168169## Anti-Patterns170171- Hardcoding Salesforce credentials -- use OAuth JWT flow or Named Credentials172- Querying all fields with `SELECT *` -- SOQL requires explicit field selection173- Bypassing the Trust Layer for direct LLM calls -- loses PII protection and audit trail174- Building custom integrations when MuleSoft connectors exist -- leverage existing connectors175- Ignoring governor limits -- Salesforce has API call limits per 24-hour period176177## References178179- [Salesforce Agentforce](https://www.salesforce.com/agentforce/)180- [Salesforce REST API](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/)181- [Einstein Trust Layer](https://www.salesforce.com/artificial-intelligence/trusted-ai/)182- [MuleSoft Connectors](https://www.mulesoft.com/exchange/)183- [Salesforce MCP Server](https://github.com/salesforce/mcp-server)184185<!-- Source: .faos/custom/skills/integrations/salesforce-agentforce/SKILL.md -->