By Sagar Shankaran, Founder of CallSphere
A developer guide to integrating AI voice agents with Salesforce — lead push, call activity logging, and managed packages.
Key takeaways
HubSpot is a REST API with sensible defaults. Salesforce is a platform with its own query language (SOQL), its own composite API batching rules, its own OAuth flavors, and dozens of permission settings that will silently block your writes. Getting an AI voice agent into Salesforce cleanly is an enterprise-grade integration task, not a weekend project.
This guide walks through the integration patterns CallSphere uses for enterprise customers — JWT Bearer OAuth, composite API writes, call activity logging, and lead capture.
caller → voice agent
│
│ tool: lookup_lead_by_phone
▼
SOQL query
│
▼
Lead / Contact / Account
│
▼
Task (type=Call) inserted via composite API
┌────────────────────┐
│ Voice agent edge │
└─────────┬──────────┘
│ tool call
▼
┌──────────────────────────┐
│ /salesforce service │
│ • JWT Bearer OAuth │
│ • Composite API batching │
│ • Bulk API 2.0 fallback │
└──────────┬───────────────┘
│
▼
┌──────────────────────────┐
│ Salesforce org │
└──────────────────────────┘
simple-salesforce Python library or jsforce for Node.Server-to-server. No user interaction. Re-used across calls.
sequenceDiagram
autonumber
participant Caller as Caller
participant Agent as CallSphere Agent
participant API as CRM API
participant DB as CRM Database
participant Webhook as Webhook Listener
Caller->>Agent: Inbound call begins
Agent->>Agent: STT plus intent detection
Agent->>API: Lookup contact by phone
API->>DB: Read contact record
DB-->>API: Contact and history
API-->>Agent: Personalized context
Agent->>API: Create call activity
Agent->>API: Update deal stage
API->>Webhook: Outbound webhook fires
Webhook-->>Agent: Confirmed
Agent->>Caller: Spoken confirmation
import jwt, time, requests
from simple_salesforce import Salesforce
def get_access_token():
claim = {
"iss": SF_CLIENT_ID,
"sub": SF_USERNAME,
"aud": "https://login.salesforce.com",
"exp": int(time.time()) + 300,
}
assertion = jwt.encode(claim, SF_PRIVATE_KEY, algorithm="RS256")
resp = requests.post(
"https://login.salesforce.com/services/oauth2/token",
data={
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion": assertion,
},
)
resp.raise_for_status()
body = resp.json()
return body["access_token"], body["instance_url"]
token, instance = get_access_token()
sf = Salesforce(instance_url=instance, session_id=token)
async def find_lead(phone: str):
soql = f"""
SELECT Id, FirstName, LastName, Company, Status
FROM Lead
WHERE Phone = '{phone}' OR MobilePhone = '{phone}'
LIMIT 1
"""
rows = sf.query(soql)["records"]
return rows[0] if rows else None
Salesforce's canonical "call activity" object is a Task with Type = 'Call'. Use the composite API to insert the task and update the lead in one round trip.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
def log_call(lead_id: str, subject: str, description: str, duration_sec: int):
payload = {
"compositeRequest": [
{
"method": "POST",
"url": "/services/data/v60.0/sobjects/Task",
"referenceId": "newTask",
"body": {
"Subject": subject,
"Description": description,
"Type": "Call",
"Status": "Completed",
"CallDurationInSeconds": duration_sec,
"WhoId": lead_id,
"ActivityDate": "2026-04-08",
},
},
{
"method": "PATCH",
"url": f"/services/data/v60.0/sobjects/Lead/{lead_id}",
"referenceId": "updateLead",
"body": {"Status": "Working - Contacted"},
},
]
}
return sf.restful("composite", method="POST", json=payload)
def create_lead(first: str, last: str, phone: str, company: str, source: str = "AI Voice Agent"):
return sf.Lead.create({
"FirstName": first,
"LastName": last,
"Phone": phone,
"Company": company or "Unknown",
"LeadSource": source,
"Status": "New",
})
const sfTools = [
{ type: "function", name: "find_lead_by_phone", description: "Look up a Salesforce lead by phone", parameters: { type: "object", properties: { phone: { type: "string" } }, required: ["phone"] } },
{ type: "function", name: "create_lead", description: "Create a new Salesforce lead", parameters: { type: "object", properties: { first: { type: "string" }, last: { type: "string" }, phone: { type: "string" }, company: { type: "string" } }, required: ["last", "phone"] } },
{ type: "function", name: "log_call_task", description: "Log a completed call as a Task", parameters: { type: "object", properties: { lead_id: { type: "string" }, subject: { type: "string" }, description: { type: "string" }, duration_sec: { type: "number" } }, required: ["lead_id", "subject"] } },
];
Salesforce will return REQUIRED_FIELD_MISSING, INVALID_SESSION_ID, and DUPLICATES_DETECTED. Map each to a clean tool response the LLM can act on.
Sforce-Limit-Info.Lead.create. Handle the DUPLICATES_DETECTED error by surfacing the existing record.CallSphere connects to Salesforce for enterprise sales and real estate customers. The real estate stack runs 10 agents (buyer specialist, seller specialist, rental specialist, tour coordinator, qualification agent, and more) coordinated through the OpenAI Agents SDK, and the sales pod pairs ElevenLabs TTS with 5 GPT-4 specialists for discovery, qualification, demo scheduling, objection handling, and close.
The voice plane runs on the OpenAI Realtime API with gpt-4o-realtime-preview-2025-06-03, PCM16 at 24kHz, and server VAD. Salesforce writes flow through a dedicated service that batches composite requests, mirrors every write to per-vertical Postgres for auditing, and attaches sentiment and lead score from the GPT-4o-mini post-call pipeline as custom fields on the Task. CallSphere runs 57+ languages with under one second end-to-end response time.
REST for single-record writes, Bulk API 2.0 for backfills. Voice agents almost always want REST.
Yes, but the ROI is only there if you are selling to many Salesforce customers. For a single deployment, direct API is simpler.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
Check Account.IsPersonAccount. The field layout differs.
Use a separate Connected App pointed at https://test.salesforce.com for sandbox JWT auth.
Use the cometd streaming API + simulator, or a Salesforce DX scratch org.
Looking to integrate Salesforce with an AI voice agent in your org? Book a demo, see the technology page, or check pricing.
#CallSphere #Salesforce #CRM #VoiceAI #EnterpriseIntegration #SOQL #AIVoiceAgents
Written by
Sagar Shankaran· Founder, CallSphere
Sagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
A how-to for Colombian education and tutoring SMBs to answer parents and students instantly, book trial classes 24/7 in Spanish and English, and grow enrollment with a CallSphere AI agent.
Tbilisi professional-services firms serving relocating founders and IT companies use CallSphere AI voice and chat agents to answer enquiries 24/7 in English, Georgian and Russian and book consultations.
A practical how-to for Palau eco-resorts and dive operators on capturing every high-value, multilingual enquiry with a CallSphere AI voice and chat agent, while honouring Palau’s marine-conservation commitments.
How salons, spas and wellness SMBs across the UAE, Saudi Arabia and Qatar use CallSphere AI voice and chat agents to capture every booking 24/7 in Arabic, English and expat languages, and cut no-shows.
How estate agents and property managers in Luxembourg City and across the Grand Duchy use CallSphere to capture multilingual viewing and enquiry calls 24/7, GDPR compliant.
A practical guide for Senegalese logistics, freight, legal and consulting SMBs in Dakar and Thiès to capture every enquiry 24/7 with a CallSphere AI voice and chat agent in French, Wolof and English.
© 2026 CallSphere LLC. All rights reserved.
Made within New York
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.
Try Live DemoBook a DemoCalculate Your ROI