Hey there! Welcome to our blog adventure! Today, we’re diving into the world of roll-up summaries on lookup relationships, and we’re doing it the cool way—with Salesforce flows. Sure, we could go the Apex route, but let’s see what the flows magic has in store.
Get ready for a journey where we break down ‘Roll-Up Summaries on Lookup Relationships using Flows’ in a way that feels like a chat over coffee. We’re turning data handling into a breeze and making Salesforce automation your new best friend. Join us, and let’s make data management a whole lot more human and fun!
Consider the following schema that we are using for this example:
We are going to use a record trigger flow to achieve this scenario:
- Go to flow from Salesforce setup menu -> create a new triggered flow.
- Here we are going to select a child object because whenever a child creates or updates the record, we need to change its respective parent record.
- Select the Student object and configure it when a record is created or updated and optimize flow for Actions and Related record.
4. Now we need to get existing student records whose Teacher lookup is the same i.e., the parent record of a teacher is the same by filtering the record.
5. We need to create 3 variables that will store the values like Maximum Marks, Minimum Marks, and Count of Student for that teacher.
6. We will create 3 variables named:
- getCount for storing total counts of student records
- getMax for storing maximum record of students record list
- getMin for storing minimum record of students record list
Note: we are going to assign default value as the highest value for this variable
7. Now we must loop through the records and check for maximum and minimum values of child Student records.
8. Now check for the maximum record value of Student marks if we found this then we will assign it to the variable of getMax using Assignment Section.
9. Similarly, we will also check for the minimum record value of Student marks if we found this then we will assign it to the variable of getMin using Assignment Section.
10. At last, we will assign the total count of Students record using another assignment section named Assign Total Count and we will store that in our getCount variable.
11. No we will fetch the Teacher record using the Get Record element and assign it an Id similar to the Students look-up teacher Id.
12. After fetching the Teachers record now it is time to update its value. We will do this by using the update record action.
- First, we get the Teacher record by passing an Id similar to the Students look-up teacher Id.
- Second we will assign Teacher fields with flows variable of getMin, getMax and getCount.
13. This is how your flow should look like save it and activate and see the results.
14. Verify the result by creating Student and Teacher record.
Notes:
- As per the date now flow does not support after delete operation scenario. So, this might not work on the deletion of the student record i.e., deleting child records.
- The best way is to create a master-detail relationship if not then implement this using Triggers.