Skip to main content

Rollups

This document outlines the structure and usage of the rollup markdown format used in Google Docs to dynamically fetch and aggregate Salesforce data.

Overview

The rollup markdown syntax is a dynamic placeholder embedded in a Google Docs template. It retrieves data from Salesforce objects and computes an aggregation (such as SUM, COUNT, or AVG) based on specified criteria. The general format is:

{!rollup:<ParentField>:<AggregationType>:<ChildField>:<Rounding>}

Syntax Components

  • ParentField

    Refers to the Salesforce field or relationship identifier used to locate related child records. This field must point to the source object based on which the file or document is rendered. In other words, when the template is generated for a given record (such as an Account), the ParentField determines how related records (for example, Opportunities) are located in Salesforce. Example:

    Opportunity.AccountId;

    This indicates that the rollup aggregates data from all Opportunity records linked to the specific Account via the AccountId field.

  • AggregationType

    Defines the mathematical or logical operation applied to the child records in the rollup. Supported values include:

    SUM — Totals numeric values, such as amounts or quantities. Example: Summing all Opportunities’ Amount fields to get total revenue for an Account.

    {!rollup:Opportunity.AccountId:SUM:Amount}

    MIN — Returns the smallest numeric or date value among the related child records. Example: Finding the earliest Close Date from related Opportunities.

    {!rollup:Opportunity.AccountId:MIN:CloseDate}

    MAX — Returns the largest numeric or date value among the related child records. Example: Finding the highest Opportunity Amount associated with an Account.

    {!rollup:Opportunity.AccountId:MAX:Amount}

    AVG — Computes the average of numeric fields across child records. Example: Calculating the average deal size for all Opportunities under an Account.

    {!rollup:Opportunity.AccountId:AVG:Amount}

    COUNT — Counts all related child records regardless of field values. Example: Counting how many Contact records are linked to an Account.

    {!rollup:Contact.AccountId:COUNT}

    COUNT_DISTINCT — Counts the number of unique values for the specified child field. Example: Counting the number of unique Products sold in related Opportunity Line Items.

    {!rollup:OpportunityLineItem.OpportunityId:COUNT_DISTINCT:Product2Id}
  • ChildField

    Specifies the field in the child object from which to aggregate data. This field determines which data attribute from the related child records is used for the calculation or aggregation defined by the AggregationType.

    Note: For the COUNT aggregation, specifying a ChildField is not necessary because it simply counts the number of related child records regardless of any specific field values.

    Example

    {!rollup:Opportunity.AccountId:SUM:Amount}

    Object Relation: From Account to Opportunity via AccountId Operation: Calculate the sum Field: Amount on Opportunity records Result: Total Opportunity Amount for each Account

    When executed, this expression dynamically replaces the placeholder with the computed sum of all related Opportunity Amount values for the current Account record.

    Example without ChildField (for COUNT)

    {!rollup:Contact.AccountId:COUNT}

    Object Relation: From Account to Contact via AccountId Operation: Count the number of related Contact records Field: Not required for COUNT Result: Total number of Contacts linked to each Account

    This counts how many Contacts exist for each Account without referring to any specific field on the Contact object.

  • Rounding (Optional)

    The optional fourth parameter Rounding defines the number of decimal places to which the aggregated result is rounded.

    • If not provided, the default rounding precision is 2 decimal places.
    • This parameter is only applicable for aggregation types that produce numeric results (e.g., SUM, AVG, MIN, MAX).
    • For the COUNT aggregation (which does not require a child field), you cannot provide a rounding parameter because count results are always whole numbers.

    Example Usage with Rounding

    {!rollup:Opportunity.AccountId:SUM:Amount:3}

    Aggregates the sum of the Amount field from Opportunities related to the Account. Result is rounded to 3 decimal places instead of the default 2.

    Example Without Rounding (defaults to 2 decimal places)

    {!rollup:Opportunity.AccountId:AVG:Amount}

    Calculates the average Amount. Result is rounded to 2 decimal places by default.

    Example Without ChildField and Rounding (COUNT)

    {!rollup:Contact.AccountId:COUNT}

    Counts number of Contacts related to an Account. No rounding parameter allowed.

Supported Use Cases

  • Summarizing related record values in automated Google Doc templates
  • Displaying total revenue per Account, number of Contacts per Account, or average deal size
  • Integrating Salesforce datasets into formatted documents with automated aggregation

Notes and Best Practices

  • Ensure field API names are correct and correspond to Salesforce schema.
  • Only numeric or date fields can be used with SUM, AVG, MIN, or MAX.
  • COUNT ignores the ChildField parameter, use:
{!rollup:Object.Relationship:COUNT}