4. Salesforce Admin Group, Trichy
• Meetup Success
• Public Interest
• Social Media promotions
• Leader contribution
• Previous meetups
• Achievement
• Admin path
5. Today’s Agenda
• What is a Roll-Up summary Field?
• What is the necessity of automation?
• What all are the limitations of Roll-Up
• What alternative solutions do we have?
• Demo
• Questions & Answers
• Conclusion
6. What is a Roll-Up summary Field?Logo
• Roll-up summary is a built-in functionality in Salesforce. They allow
you to create Sums, Counts, and more for objects that share a Master-
Detail relationship.
• Cannot use Roll-Up Summary fields to create a Sum or Count for
objects related with a Lookup field
• The Roll-up field automatically looks for the change in related records
and automatically updates the Master record.
7. Continued…Logo
• This can be created only when the relationship between Parent
and child is ‘Master-Detail’ Relation.
8. ExampleLogo
we have ‘Admin’ object, which his having a ‘Trichy’ as Child
Object. We can calculate the number of child objects exists
for the ‘Admin’ and display them in the ‘Admin’ object.
When a new ‘Trichy’ is added, the roll-up summary field in
‘Admin’ is updated automatically.
10. What is the necessity of automation?Logo
There are two more options to create a roll-up field without MD
relationship.
• Apex code
• Automation process
Why we choose Automation over apex code?
We can integrate different Automation tools like Process Builder and
Auto launched Flow to perform a complex process and can even call
Apex code from the tools. In short, they have made the jobs of
Salesforce Administrators easier.
11. Automation TypesLogo
Automation process has
divided into four different
types based on the
functionality
• Workflow
• Process Builder
• Approval Process
• Flow Builder
12. What all are the limitations of Roll-Up summary fieldLogo
• A Roll-up summary can be created only on records which are having
Master-Detail Relationship.
• A Master-detail relationship can’t be changed to lookup relationship
after creating a roll-up summary field on an object.
• When you refer to a roll-up summary field in a list view or report, you
can’t use certain qualifiers, including: Starts with Contains, Does not
contain, Includes, Excludes and Within.
13. What alternative solutions do we have?Logo
Now we can be able to create a Sum, Count, Min and Max field to
populate values on objects that do not share a Master-Detail
relationship using either Automation or Developing concepts
• Apex/Trigger
• Flow/Process Builder
Screen Flow
Auto-Launched Flow(Flow with Process Builder)
Triggered Flow
Lightning Scheduler Flow
14. Apex TriggerLogo
trigger ApexRollUpSummaryTrigger on Trichy__c (after insert, after update, after delete, after undelete)
{
if (trigger.isAfter && (trigger.isInsert || trigger.isUpdate || trigger.isUndelete))
{
ApexRollUpSummary.sumofMembers(trigger.new);
}
else if (trigger.isAfter && trigger.isDelete)
{
ApexRollUpSummary.sumofMembers(trigger.old);
}
}
15. Apex ClassLogo
public class ApexRollUpSummary
{
public static void sumofMembers(list<Trichy__c> lstOfMembers)
{
Set<Id> adminIds = new Set<Id>();
List<Admin__c> updLstOfAdm = new List<Admin__c>();
List<Trichy__c> memberList = new List<Trichy__c>();
for(Trichy__c trichy : lstOfMembers)
{
if(trichy.Admin__c != null)
adminIds.add(trichy.Admin__c);
}
16. ContinuationLogo
List<Admin__c> lstAdm = [SELECT Id,Name,Total_Members__c, (SELECT
Id,Group_Members__c FROM Trichys__r) FROM Admin__c WHERE Id IN : adminIds];
for(Admin__c adm : lstAdm)
{
decimal total = 0;
if(adm.Trichys__r.size() >0)
for(Trichy__c tcy : adm.Trichys__r)
{
if(tcy.Group_Members__c != null)
total = total+tcy.Group_Members__c;
21. Challenges in ApexLogo
• Need to maintain all the insert and update events in a single
trigger for a single object (As part of best practice)
• Need to have handler logic in separate apex class.
• Mandatorily should write apex test class and have test
coverage of above 75% for and every class.
• Test class should cover positive, negative and bulk scenarios
(As part of best practice).
• Need to have trigger switch in order to turn it off in
production.
24. Conclusion
• Sometimes Apex code also depend on Automation process
• New version of Flow contains all those options which is available after
wrote a huge lines of code in Apex.
• Initially process builder doesn’t have “Delete” option but that would be
overcome by Flow builder
• As a Low Code Lover, I would suggest to go with Automation