Although Salesforce allows you to do Rollups between master-detail relationships, in some cases you might need a parent-child relationship or a lookup relationship. Fonteva allows you to create Rollup Summaries for lookup relationships. These Rollups allow you to perform operations such as Sum, Count and Concatenate on related objects, not just those in a master-detail relationship.
For example, if you want the number of Contacts on an Account to update each time there's a new Contact for that account, you would use a Rollup Summary.
Each Rollup Summary is executed in its own queueable context. If you have five Rollups, they execute sequentially one Rollup at a time until all Rollups are updated. Because this is asynchronous code, Salesforce allows 200 SOQL query operations. While there is no technical limit on the number of Rollups you can create on a single sObject, Fonteva recommends a limit of 10 to avoid longer execution times or hitting governor limits.
When a new Rollup Summary is created, a new Custom Setting record is created in Salesforce. This custom setting is only available in Fonteva's Framework. That data is read on each trigger execution to figure out which Rollups must be fired. This is determined by the SOQL Where clause built by the filter criteria you specify in your Rollup Summary.
- Fonteva recommends not enabling batching. When you enable batching, your Rollups will not update in real-time. Instead, each Rollup will run individually as part of a scheduled batch. Instead of running differentially, the batched rollups will run the entire data set.
- If the Rollup Summary is set to batchable and doesn't update, verify the job is running or has run in your Apex Job Queue.
Create a New Rollup Summary
From the Rollup Summary Fields Dashboard:
- [Click] .
- [Choose] the following:
- Parent SObject - The name of the parent sObject.
- Parent Field - The specific field within the parent sObject.
- Child SObject - The name of the dependent sObject.
- Relationship Field - The destination field.
- Child Field - The specific field within the dependent sObject.
- Sum - The sum of two field values.
- Max and Min - This filters data based on a minimum and maximum value.
- Avg - This calculates the average value of a data set.
- Count - While you can use this operation on any field, Fonteva recommends only using this for ID fields.
- Concatenate: This will take all the child fields and place them in a comma-separated list.
- Concatenate_Distinct: This will create the same list as above without allowing duplicates.
- [Enter] an SOQL Filter if needed. This filter is inserted into a SOQL Where clause.
- [Click] the Is Enabled select box.
- [Click] the Enable Trigger select box to execute the triggers associated with the Parent SObject. This is enabled by default. If you deselect this, only the Rollup Field is updated. No other fields associated with the Parent SObject are updated.
- [Click] the Enable Batching select box to have the Rollups execute as part of a scheduled batch.
- [Enter] the following:
- Parent Batch Scope
- Child Batch Scope
- [Click] .
Fonteva also allows you to create new Rollup Summaries by injecting code into your Fonteva app via the Developer's Console.
Framework.RollupSummaryField rsf6 = new Framework.RollupSummaryField(); rsf6.namespace = PackageUtils.namespace; rsf6.childField = SObjectType.Registration_Item__c.fields.Id.getName(); rsf6.childSObject = SObjectType.Registration_Item__c.getName(); String sFilter6; sFilter6 = SObjectType.Registration_Item__c.fields.Status__c.getName() + ' = \'Registered\' '; sFilter6 += ' OR ' + SObjectType.Registration_Item__c.fields.Status__c.getName() + '= \'Invited\' '; rsf6.filter = sFilter6; rsf6.operation = Framework.RollupSummaryField.Operation.Count.name(); rsf6.parentField = Framework.SchemaService.getDescribe(Schedule_Item__c.Quantity_Sold__c).getName(); rsf6.parentSObject = Framework.SchemaService.getDescribe(Schedule_Item__c.SObjectType).getName(); rsf6.relationshipField = Framework.SchemaService.getDescribe(Registration_Item__c.Schedule_Item__c).getName(); rsf6.isEnabled = true; rsfs.add(rsf6);
- You can use formula fields as a Child Field or in Filter Criteria.
- A Rollup Summary cannot be triggered by a change in a formula field value. An edit action must occur to trigger the Rollup when a value is changed.
- If you have multiple variables in you Filter, you must enclose them in parentheses.
- When a Rollup summary is deleted, all triggers are fired.