Hi!
Thank you in advance for any advice you can provide. I'm trying to design a flow. Ideally, when an opportunity record is updated, the flow would look at the related account record. On the account record, there are grades K-12. Each relevant grade field will have the total number of students. Depending on the opportunity, some of the grade level fields may not be filled in. For example, if the opportunity is a K-5 school, then the 6-12 grade level fields on the account record won't be filled in.
Ideally, the flow would pull the grade level fields if the field is filled in, calculate the average, and add the average to the opportunity record.
Any idea how to design this flow?
#Flows #Automation #Formulas #Help #Flow
Divya Chauhan (Kcloud Technologies) Forum Ambassador
Hello @Jessica Lamadieu
Salesforce Flow to Calculate Average Students (K-12) on Opportunity Update-
1. Record-Triggered Flow: Create a Flow for Opportunity on Update.
2. Get Account: Use Records to fetch the related Account via Account ID.
3. Variables: Create totalStudents (Number,0) and filledFieldsCount(Number,0).
4.L oop Grades: Loop through grade fields(K-1 ,e.g., Grade_K__c).for non-null/non-zero fields:
Add value to totalStudents.
Increment the filled Fields Count.
5 . Calculate Average: If filledFieldsCount > 0, compute the total student filledFieldsCount and store it in averageStudents.
6. Update Opportunity: Set Avrage_Students__c on Opportunity to averageStudents.
7 . Error Handling: Add fault path for Get Records and check filledFieldCount to avoid division by zero.
8. Tes:S ave as Calc_Avg_Students_Opportunity test with varied grade data.