Skip to main content
Glama

Salesforce MCP Server

salesforce_aggregate_query

Execute SOQL queries with GROUP BY and aggregate functions to summarize and analyze Salesforce data. Use for grouping records, applying statistical functions, and filtering results with WHERE and HAVING clauses.

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

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

Input Schema (JSON Schema)

{ "properties": { "groupByFields": { "description": "Fields to group by - must include all non-aggregate fields from selectFields", "items": { "type": "string" }, "type": "array" }, "havingClause": { "description": "HAVING clause to filter results AFTER grouping (use for aggregate conditions)", "optional": true, "type": "string" }, "limit": { "description": "Maximum number of grouped results to return", "optional": true, "type": "number" }, "objectName": { "description": "API name of the object to query", "type": "string" }, "orderBy": { "description": "ORDER BY clause - can only use grouped fields or aggregate functions", "optional": true, "type": "string" }, "selectFields": { "description": "Fields to select - mix of group fields and aggregates. Format: 'FieldName' or 'COUNT(Id) AliasName'", "items": { "type": "string" }, "type": "array" }, "whereClause": { "description": "WHERE clause to filter rows BEFORE grouping (cannot contain aggregate functions)", "optional": true, "type": "string" } }, "required": [ "objectName", "selectFields", "groupByFields" ], "type": "object" }

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/tsmztech/mcp-server-salesforce'

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