Loading
Automate Your Business Processes
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Create a Before-Save Flow for Better Data Quality

          Create a Before-Save Flow for Better Data Quality

          Create a before-save record-triggered flow that validates data quality and enforces business rules before course attendee records are created. No matter how a course attendee is created, this flow prevents duplicate enrollments, validates course capacity, and ensures data integrity by blocking invalid records and setting appropriate statuses based on business logic.

          Required Editions

          View supported editions.
          User Permissions Needed
          To open, edit, create, activate or deactivate a flow using all flow types, elements, and features available in Flow Builder, including Einstein and Agentforce for Flow: Manage Flow

          This sample flow works in conjunction with the other sample flows in Automate a Course Management Process Project.

          This before-save flow runs during the record creation process, before the course attendee record is saved to the database. By optimizing for fast field updates, the flow intercepts the save operation and validates the data at the moment of creation. First, it checks if an identical course attendee record already exists by querying for records with the same contact and course delivery. If a duplicate is found, the flow immediately blocks the save with a custom error message, preventing bad data from entering the system. If the record is unique, the flow then checks the course delivery capacity by counting existing attendees and comparing it to the maximum allowed. Based on this count, the flow automatically sets the new attendee's status to either Enrolled or Waitlisted and generates a confirmation code for enrolled attendees. This approach ensures that data validation happens consistently regardless of how the record is created—whether through the UI, API, data import, or a screen flow—and guarantees that business rules are enforced before any invalid data reaches the database.

          1. Open the Flows list view.
            • From Setup, in the Quick Find box, enter Flows, and then select Flows.
            • From the Automation app, select the Flows tab.
            • From the Flows tab in any Lightning app, click the actions menu and select Open Flow.
          2. Create a record-triggered flow.
            1. From the Automation app, click New. Select Triggered Automations, and then select Record-Triggered Flow.
            2. From Setup, click New Flow, select Triggered Automations, and then select Record-Triggered Flow.
            The Configure Start panel opens.
          3. Configure the Start element.
            1. On the Configure Start panel, for Object, select Course Attendee.
            2. For Trigger the Flow When, select A record is created.
            3. For Optimize the Flow for, select Fast Field Updates.
          4. Get all records with the same course attendee and course delivery as the new record with a Get Records element.
            1. Click Add element plus icon, and select Get Records.
              The Get Records panel opens.
            2. For Label, enter Get Duplicate Records.
              The API name auto-fills.
            3. For Description, enter Gets all course attendee records that have the same contact ID and course record ID as the triggering record. Stores the result in the Course Attendees from Get Duplicate Records record collection.
            4. For Object, select Course Attendee.
            5. For Field, select Attendee.
            6. For Operator, select Equals.
            7. For Value, select Triggering Course_Attendee__c > Attendee > Contact ID.
            8. Click + Add Condition.
              A second filter condition is added to the Get Records element.
            9. For Field, select Course Delivery.
            10. For Operator, select Equals.
            11. For Value, select Triggering Course_Attendee__c > Course Delivery > Record ID.
            12. For How Many Records to Store, select All records.
          5. Determine whether the Get Records element returned any records with a Decision element.
            1. Click Add element plus icon, and select Decision.
              The Decision panel opens.
            2. For Label, enter Found Duplicate Records?.
              The API name auto-fills.
            3. For Description, enter Determines whether any duplicate course attendee records were found in Get Duplicate Records.
            4. For Select Decision Logic, select Define Manually (Default).
            5. For Outcome Label, enter Yes.
            6. For Outcome API Name, enter IsDuplicateRecord.
            7. For Resource, select Course Attendees from Get Duplicate Records.
            8. For Operator, select Is Null.
            9. For Value, select False.
            10. Under Outcome Order, select Default Outcome.
            11. For Label, enter No.
          6. Add a custom error when the new record is a duplicate with a Custom Error element.
            1. In the Yes path, click Add element plus icon, and select Custom Error.
              The Custom Error Message panel opens.
            2. For Label, enter Create a Duplicate Record Error Message.
              The API name auto-fills.
            3. For Description, enter Sets off a custom error message and prevents the triggering course attendee record from being created.
            4. For Error Message, enter We couldn't create this record because it already exists.
          7. Make the custom error the last element in the Yes path.
            1. In the Yes path, after the Custom Error Message element, click Add element plus icon, and then select End.
              The last element in the Yes path is an End element.
          8. Get all course attendee records with the same course as the new record with a Get Records element.
            1. In the No path, click Add element plus icon, and select Get Records.
              The Get Records panel opens.
            2. For Label, enter Get All Course Attendees.
              The API name auto-fills.
            3. For Description, enter Gets all course attendee records with a course delivery record ID that matches the course delivery record ID of the triggering record. Stores the result in the Course Attendees from Get All Course Attendees record collection.
            4. For Object, select Course Attendee.
            5. For Field, select Course Delivery.
            6. For Operator, select Equals.
            7. For Value, select Triggering Course_Attendee__c > Course Delivery > Record ID.
            8. For How Many Records to Store, select All records.
          9. Add a variable to store a count of how many records the Get Records element returned.
            1. To open the Toolbox, click Toolbox icon..
            2. Click New Resource, and then select Variable.
            3. For API Name, enter AttendeeCount.
            4. For Description, enter Stores the number of attendees for the course delivery of the triggering record.
            5. For Data Type, select Number.
            6. For Decimal Places, enter 0.
            7. Click Done.
          10. Store the number of course attendee records for the course in the AttendeeCount variable with an Assignment element.
            1. After the Get All Course Attendees element, click Add element plus icon, and select Assignment.
              The Assignment panel opens.
            2. For Label, enter Set AttendeeCount Variable.
              The API name auto-fills.
            3. For Description, enter Sets the value of the AttendeeCount variable to the number of records returned by Get All Course Attendees.
            4. For Variable, select AttendeeCount.
            5. For Operator, select Equals Count.
            6. For Value, select Course Attendees from Get All Course Attendees.
          11. Determine whether the course delivery is fully enrolled with a Decision element.
            1. After the Set AttendeeCount Variable element ,click Add element plus icon, and select Decision.
              The Decision panel opens.
            2. For Label, enter Is Course Delivery Full?.
              The API name auto-fills.
            3. For Description, enter Determines whether the count of course attendees for the course delivery of the triggering record is greater than or equal to the maximum attendees allowed for the course delivery.
            4. For Select Decision Logic, select Define Manually (Default).
            5. For Outcome Label, enter Yes.
            6. For Outcome API Name, enter IsFull.
            7. For Resource, select AttendeeCount.
            8. For Operator, select Greater Than or Equal.
            9. For Value, select Triggering Course_Attendee__c > Course Delivery > Maximum Attendees.
            10. Under Outcome Order, select Default Outcome.
            11. For Label enter No.
          12. If the class is full, set the course attendee status to Waitlisted with an Assignment element.
            1. In the Yes path, click Add element plus icon, and select Assignment.
              The Assignment panel opens.
            2. For Label, enter Set Triggering Record Status to Waitlisted.
              The API name auto-fills.
            3. For Description, enter Sets the status of the triggering record to Waitlisted.
            4. For Field, select Triggering Course_Attendee__c > Status.
            5. For Operator, select Equals.
            6. For Value, select Waitlisted.
          13. Make the Assignment element the last element in the Yes path.
            1. In the Yes path after the Assignment element, click Add element plus icon, and select End.
              The last element in the Yes path is an End element.
          14. Create a formula to generate a course confirmation code.
            1. To open the Toolbox, click Toolbox icon..
            2. Click New Resource, and then select Formula.
            3. For API Name, enter CourseConfirmationCode.
            4. For Description, enter Generates a course confirmation code that contains the last name of the course attendee, the month, day, and year of the course delivery and the first 10 characters of the course name.
            5. For Data Type, select Text.
            6. For Formula, enter this text: "CRC–" & {!$Record.AttendeeId__r.LastName} & "–" & TEXT(MONTH(TODAY())) & "–" & TEXT(DAY(TODAY())) & "–" & TEXT(YEAR(TODAY())) & "–" & LEFT({!$Record.CourseDeliveryId__r.CourseId__r.Name}, 10)
            7. Click Check Syntax.
              If you followed the steps from Create Your Data Model, the formula is valid.
            8. Click Done.
          15. If the class isn't full, set the course attendee status and the confirmation code with an Assignment element.
            1. In the No path, click Add element plus icon, and select Assignment.
              The Assignment panel opens.
            2. For Label, enter Set Triggering Record Fields.
              The API name auto-fills.
            3. For Description, enter Sets the status and confirmation code fields of the triggering record.
            4. For Field, select Triggering Course_Attendee > Status.
            5. For Operator, select Equals.
            6. For Value, select Enrolled.
            7. Click + Add Assignment
            8. For Field, select Triggering Course_Attendee > Confirmation Code.
            9. For Operator, select Equals.
            10. For Value, select CourseConfirmationCode.
          16. Save the record-triggered flow.
            1. Click Save.
            2. For Flow Label, enter Manage New Course Attendee Records.
              The Flow API Name auto-fills.
            3. For Description, enter Manages new course attendee records before they’re saved, preventing duplicate and invalid records and setting relevant course attendee field values.
            4. Click Save.
            The completed before-save record triggered flow for new course attendee records.
           
          Loading
          Salesforce Help | Article