Agentforce Platform | Query Records with Aggregate
Answers aggregation questions about Salesforce data, such as count, sum, average, max, min, and group-by.
Required Editions
| Available in: Lightning Experience |
| Available in: Enterprise, Performance, Unlimited, and Developer Editions with Foundations, or Agentforce 1 or Einstein 1 Editions |
| User Permissions Needed | |
|---|---|
| See Common User Access for Standard Agent Actions. | |
Action Details
| API Name | QueryRecordsWithAggregate |
| Reference Action Type | Standard Action |
| Does this action execute one or more prompt templates? | No |
Considerations
- This action supports only English language.
- This action works with any searchable standard objects supported by the User Interface API and any searchable custom objects. External objects are not supported.
- Aggregated queries on related objects aren’t supported. For example, a user can’t find out how many accounts have multiple contacts.
- Queries with data from multiple objects aren’t supported. For example, a user can’t view their leads and opportunities with one request.
- Queries that retrieve data based on a lookup field, related list, or a picklist don’t always work.
- Field normalization isn’t available, so retrieving records based on field values is format-dependent. For example, the user request “Get my contacts with phone number 415-123-4567” returns results only if the phone number is entered in the exact same format.
- Queries with ambiguous filter or sort criteria are determined by the LLM. No specific business rules are used. For example, if a user wants to get a count of their “top” opportunities, the LLM can interpret “top” to mean the opportunities with the highest amount or soonest close date. If you have questions about the criteria used to retrieve the search results, view the plan in Agentforce Builder.
- Synonyms are supported for common standard objects and fields. For example, if a user’s request includes the word “deal,” the action can determine that the user is referring to an opportunity. Customization of synonyms isn’t supported. Synonyms for custom objects or fields aren’t always interpreted accurately.
- A limited set of default standard fields for the Account, Contact, Case, Opportunity, and Lead objects are supported. Other fields are supported only if they're included in the queried object’s default searchable layout and the default record page layout. If the object has a large number of fields, the action can limit the number of fields included in the search.
- When results are returned, the displayed fields come from two sources: up to three
fields from the query and up to 10 fields from the object’s search layout. These sets are
merged, and any field that appears in both is counted only once. As a result, the number
of displayed fields varies and isn’t always a fixed total of 10. If the query has fewer
than three fields, only those queried fields are included from the query. If the query has
more than three fields, only three are included.
- Fewer than three query fields: For example, if a user asks to see their opportunities sorted by rating, the query contributes two fields (Opportunity Name and Rating), and the search layout contributes five fields (Opportunity Name, Stage, Close Date, Owner, and Account Name). Because Opportunity Name appears in both sources, it’s counted only once, so the user sees six fields.
- More than three query fields: For example, if a user asks to see their accounts with the name, industry, annual revenue, and phone, the query has four fields, so only the first three are kept: Account Name, Industry, and Annual Revenue. Phone is dropped from the query, though it can still appear if it’s part of the account search layout.
- Results are returned only when the full search criteria are met. Partial results aren’t supported. If a user requests information based on two fields but they only have access to one of those fields, the query returns an error instead of returning results based on just one of the fields.
- If a query aggregates a large number of records, the action can time out or fail to process. For example, a request to find the sum of all open opportunities can fail if your organization has thousands of opportunity records. Users can provide more specific criteria to limit the search.
- Implicit field lookups aren't fully supported. To retrieve records with a specific field match, mention the precise field and value in the query. For example, for more accurate results, a user can enter, “How many accounts have an Industry of Technology?” rather than "How many technology accounts do I have?
Did this article solve your issue?
Let us know so we can improve!

