Salesforce Named Query API: REST Endpoints Without Writing Apex
Winter '26 Beta feature that eliminates boilerplate data access code
Named Query API lets you define SOQL in Setup and get a REST endpoint automatically—no Apex, no deployment, no test classes.
Setup: Setup → Integrations → Named Query API → Define SOQL with :paramName bind variables → Save
Result: /services/data/v66.0/named/query/YourQueryName
Best for: External integrations, Agentforce actions, replacing simple query-wrapper Apex classes
The Problem
You need to expose Salesforce data to an external app. So you write an Apex class with @RestResource, add a SOQL query, write a test class, deploy it, and maintain it forever. Five lines of logic, forty lines of ceremony.
Named Query API skips all of that.
How It Works
1. Define the query in Setup:
SELECT Id, Name, Amount, StageName, Account.Name
FROM Opportunity
WHERE StageName = :stage AND Amount >= :minAmount
ORDER BY Amount DESC
LIMIT :maxRecords
2. Call the generated endpoint:
import requests
response = requests.get(
"https://yourorg.my.salesforce.com/services/data/v66.0/named/query/HighValueOpps",
headers={"Authorization": f"Bearer {token}"},
params={"stage": "Negotiation", "minAmount": 100000, "maxRecords": 25}
)
for opp in response.json()["records"]:
print(f"{opp['Name']}: ${opp['Amount']:,.0f}")
That's it. Salesforce handles parameter validation, FLS, and sharing rules automatically.
Agentforce Integration
Named Queries shine as agent actions. Instead of writing Apex invocable methods, you point an action at a Named Query.
Named Query: MyOpenOpportunities
SELECT Id, Name, Amount, StageName, CloseDate, Account.Name
FROM Opportunity
WHERE OwnerId = :userId AND IsClosed = false
ORDER BY CloseDate ASC
LIMIT :maxRecords
Agent Action Config:
action = {
"name": "Get_My_Pipeline",
"source": "NamedQuery:MyOpenOpportunities",
"inputs": [
{"name": "userId", "source": "CONTEXT", "value": "$User.Id"},
{"name": "maxRecords", "default": 10}
]
}
User asks: "What's in my pipeline?"
Agent calls: Get_My_Pipeline → Named Query executes → Returns opportunities
Agent responds:
You have 8 open deals worth $1.2M. Three are closing this month: Acme ($250k), TechCorp ($180k), and GlobalCo ($95k).
No Apex. No Flow. No hallucinated SOQL.
When to Use It
| ✅ Use Named Query | ❌ Use Apex Instead |
|---|---|
| Read-only data access | Write operations |
| Stable, known query patterns | Dynamic field selection |
| Agentforce data retrieval | Complex transformations |
| External integrations | Aggregate queries |
Limitations (Beta)
- Read-only (no DML)
- No GROUP BY / aggregates
- Static field list
- API may change before GA
Bottom Line
If you have Apex classes that exist solely to wrap a SOQL query and return results, Named Query API replaces them with zero code. For Agentforce, it's the cleanest way to give agents structured data access.
References: Salesforce Winter '26 Release Notes, REST API Developer Guide