Skip to main content
Glama
aaron-pienza

Salesforce MCP Server

by aaron-pienza

salesforce_aggregate_query

Execute aggregate SOQL queries with GROUP BY, HAVING, and functions like COUNT, SUM, AVG, MIN, MAX to summarize Salesforce data for analysis.

Instructions

Execute SOQL queries with GROUP BY, aggregate functions, and statistical analysis. Use this tool for queries that summarize and group data rather than returning individual records.

NOTE: For regular queries without GROUP BY or aggregates, use salesforce_query_records instead.

This tool handles:

  1. GROUP BY queries (single/multiple fields, related objects, date functions)

  2. Aggregate functions: COUNT(), COUNT_DISTINCT(), SUM(), AVG(), MIN(), MAX()

  3. HAVING clauses for filtering grouped results

  4. Date/time grouping: CALENDAR_YEAR(), CALENDAR_MONTH(), CALENDAR_QUARTER(), FISCAL_YEAR(), FISCAL_QUARTER()

Examples:

  1. Count opportunities by stage:

    • objectName: "Opportunity"

    • selectFields: ["StageName", "COUNT(Id) OpportunityCount"]

    • groupByFields: ["StageName"]

  2. Analyze cases by priority and status:

    • objectName: "Case"

    • selectFields: ["Priority", "Status", "COUNT(Id) CaseCount", "AVG(Days_Open__c) AvgDaysOpen"]

    • groupByFields: ["Priority", "Status"]

  3. Count contacts by account industry:

    • objectName: "Contact"

    • selectFields: ["Account.Industry", "COUNT(Id) ContactCount"]

    • groupByFields: ["Account.Industry"]

  4. Quarterly opportunity analysis:

    • objectName: "Opportunity"

    • selectFields: ["CALENDAR_YEAR(CloseDate) Year", "CALENDAR_QUARTER(CloseDate) Quarter", "SUM(Amount) Revenue"]

    • groupByFields: ["CALENDAR_YEAR(CloseDate)", "CALENDAR_QUARTER(CloseDate)"]

  5. Find accounts with more than 10 opportunities:

    • objectName: "Opportunity"

    • selectFields: ["Account.Name", "COUNT(Id) OpportunityCount"]

    • groupByFields: ["Account.Name"]

    • havingClause: "COUNT(Id) > 10"

Important Rules:

  • All non-aggregate fields in selectFields MUST be included in groupByFields

  • Use whereClause to filter rows BEFORE grouping

  • Use havingClause to filter AFTER grouping (for aggregate conditions)

  • ORDER BY can only use fields from groupByFields or aggregate functions

  • OFFSET is not supported with GROUP BY in Salesforce

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
objectNameYesAPI name of the object to query
selectFieldsYesFields to select - mix of group fields and aggregates. Format: 'FieldName' or 'COUNT(Id) AliasName'
groupByFieldsYesFields to group by - must include all non-aggregate fields from selectFields
whereClauseNoWHERE clause to filter rows BEFORE grouping (cannot contain aggregate functions)
havingClauseNoHAVING clause to filter results AFTER grouping (use for aggregate conditions)
orderByNoORDER BY clause - can only use grouped fields or aggregate functions
limitNoMaximum number of grouped results to return
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Without annotations, the description fully discloses behavioral traits: it explains the query processing order, restrictions (e.g., no OFFSET with GROUP BY), and field inclusion rules. It also clarifies what the tool does not handle (regular queries). There is no contradiction with structured fields.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections, bullet points, and numbered examples. It front-loads the core purpose and usage distinction. Every sentence adds value, and despite length, it is concise for the complexity of the tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (7 parameters, no output schema), the description provides comprehensive coverage: examples for multiple use cases, important rules, and limitations. It sufficiently prepares an agent to use the tool correctly without needing external information.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, each parameter is described. The description adds significant meaning beyond the schema through detailed examples, formatting guidance (e.g., selectFields with aliases), and explanations of WHERE vs HAVING. This high-quality elaboration justifies above baseline 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool executes SOQL queries with GROUP BY and aggregate functions, contrasting with 'salesforce_query_records' for simple queries. It distinguishes by explicitly noting it's for summarizing data rather than returning individual records.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly tells when to use this tool versus 'salesforce_query_records' and provides important rules for usage, such as requiring non-aggregate fields in GROUP BY, filtering order (WHERE before GROUP, HAVING after), and constraints on ORDER BY and OFFSET.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aaron-pienza/mcp-server-salesforce'

If you have feedback or need assistance with the MCP directory API, please join our Discord server