# How do custom summary formulas and rollups enhance pipeline analytics on parent accounts?

**Topic:** Sales Cloud · **Difficulty:** Medium · **Tags:** Sales Cloud, Analytics, Rollup Summaries

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-custom-summary-formulas-and-rollups-enhance-pipeline-analytics-on-parent-accounts

## Answer

**Basics:** Roll-up summary fields exist only on the master side of a master-detail relationship, supporting COUNT, SUM, MIN and MAX (no average). Opportunity to Account is a lookup, so you need another route to put Open Pipeline or Weighted Pipeline on an Account. Custom summary formulas are different: they are report-level calculations over grouped data.

**How it works:**
1. Reports: add a custom summary formula (for example weighted amount divided by count, or PARENTGROUPVAL, PREVGROUPVAL) on a summary or matrix report; up to 10 summary formulas per report. Row-level formulas work per row.
2. Flow: record-triggered flow on Opportunity that collects affected account Ids, uses Get Records or an aggregate loop, and updates the Account.
3. Apex: trigger plus handler running an aggregate SOQL grouped by AccountId, then updating accounts.
4. Declarative Lookup Rollup Summaries (open source DLRS) or an AppExchange option for configuration-only rollups.

**Advanced / deep dive:** Rollups from triggers must handle inserts, updates (including AccountId changes, so recalc both old and new account), deletes and undeletes. Hot accounts with thousands of opportunities cause row locking when many opportunities update at once; consider scheduled or queued recalculation to avoid UNABLE_TO_LOCK_ROW. Averages and win rate are derived: store sum and count, then compute with a formula field. In multi-currency orgs, convert amounts consistently. For analysis over huge volumes, use CRM Analytics, not stored rollups. Account hierarchy rollups (child accounts to parent) are a further step and are usually done by Apex or DLRS.

**Code / config example:**
```apex
public static void recalc(Set<Id> acctIds) {
  Map<Id, Account> upd = new Map<Id, Account>();
  for (Id a : acctIds) upd.put(a, new Account(Id = a, Open_Pipeline__c = 0, Weighted_Pipeline__c = 0));
  for (AggregateResult ar : [
      SELECT AccountId a, SUM(Amount) amt, SUM(ExpectedRevenue) wtd
      FROM Opportunity WHERE AccountId IN :acctIds AND IsClosed = false
      GROUP BY AccountId]) {
    Account ac = upd.get((Id) ar.get('a'));
    ac.Open_Pipeline__c = (Decimal) ar.get('amt');
    ac.Weighted_Pipeline__c = (Decimal) ar.get('wtd');
  }
  update upd.values();
}
```

**Hidden gotchas & must-remember points:**
- Standard roll-up summary needs master-detail; Account to Opportunity is a lookup.
- Roll-up summary limit is 25 per object (verify for your edition).
- Roll-up summary supports no average function.
- Trigger rollups must recalc the old account when AccountId changes.
- Report summary formulas exist only in the report, not on the record.
- Heavy rollups on hot parent records cause lock contention.

**Best practice:** Keep rollup logic in one place, recalc by account Id set, and use reports or CRM Analytics for averages and trends.

---
Source: ForceChallenges · last updated 2026-11-02
