Query Salesforce Data with SOQL and SOSL
LlamaIndex tool letting an agent run SOQL and SOSL queries against a Salesforce org.
Why it matters
Integrate with your Salesforce environment to perform SOQL and SOSL queries. This tool enables agents to retrieve and act upon customer data directly from Salesforce.
Outcomes
What it gets done
Execute SOQL queries to retrieve specific records.
Execute SOSL queries for broad searches across Salesforce objects.
Connect to Salesforce using provided credentials.
Return query results in a structured JSON format.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/li-tool-tools-salesforce | bash Overview
Salesforce Tool
The Salesforce Tool wraps the simple-salesforce library to let a LlamaIndex agent run SOQL and SOSL queries against a Salesforce org, returning decoded record data through two functions: execute_soql and execute_sosl. Use it when an agent needs to query Salesforce records. It requires Salesforce connected-app credentials: username, password, consumer key and secret, and domain.
What it does
The Salesforce Tool connects to a Salesforce environment and lets an agent run SOQL and SOSL queries against it. It is a wrapper around the simple-salesforce Python library. It exposes two functions: execute_sosl (returns a Salesforce search result, decoded from the response JSON) and execute_soql (returns the full result set for a SOQL query, with totalSize reflecting the full record count and records the full list retrieved).
When to use - and when NOT to
Use it when an agent needs to query Salesforce data -- for example "List 3 Accounts in Salesforce" or "Provide information on a customer account John Doe." It requires Salesforce credentials (username, password, consumer key, consumer secret, and a domain such as test for a sandbox), so it is not usable without an existing Salesforce org and connected-app credentials.
Inputs and outputs
Given a SOQL or SOSL query string, execute_soql/execute_sosl return the matching Salesforce records as a decoded dict. Initialize with your credentials and attach to an agent:
from llama_index.tools.salesforce import SalesforceToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
sf = SalesforceToolSpec(
username=sf_username,
password=sf_password,
consumer_key=sf_consumer_key,
consumer_secret=sf_consumer_secret,
domain="test",
)
agent = FunctionAgent(
tools=sf.to_tool_list(),
llm=OpenAI(model="gpt-4.1"),
)
print(await agent.run("List 3 Accounts in Salesforce"))
print(await agent.run("Provide information on a customer account John Doe"))
Who it's for
Developers building agents that need natural-language access to Salesforce records without writing SOQL or SOSL by hand for every request.
Source README
Salesforce Tool
This tool connects to a Salesforce environment and allow the Agent to perform SOQL and SOSL queries.
Usage
This tool is a wrapper tool using the simple salesforce library. More information on this library here
Here's an example usage of the Salesforce Tool:
from llama_index.tools.salesforce import SalesforceToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
### Initialize the tool with your Salesforce credentials and other relevant details
sf = SalesforceToolSpec(
username=sf_username,
password=sf_password,
consumer_key=sf_consumer_key,
consumer_secret=sf_consumer_secret,
domain="test",
)
agent = FunctionAgent(
tools=sf.to_tool_list(),
llm=OpenAI(model="gpt-4.1"),
)
print(await agent.run("List 3 Accounts in Salesforce"))
print(await agent.run("Provide information on a customer account John Doe"))
execute_sosl - Returns the result of a Salesforce search as a dict decoded from the Salesforce response JSON payload.
execute_soql - Returns the full set of results for the query. The returned dict is the decoded JSON payload from the final call to Salesforce, but with the totalSize field representing the full number of results retrieved and the records list representing the full list of records retrieved.
This loader is designed to be used as a way to load data as a Tool in a Agent.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.