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
          Simultaneously Update Fields in Multiple Records Example

          Simultaneously Update Fields in Multiple Records Example

          This example creates a flow that updates fields in multiple records by reassigning account ownership based on business rules.

          Required Editions

          Example of a flow that loops through a collection

          First, create an Account-based record collection variable called collReassignedAccts.

          New Resource window shows Resource Type set to Variable, API Name set to collReassignedAccts, Data Type set to Record, Allow multipile values (collection) selected, and Object set to Account

          Next, add the Get Records element to get all account records that John Smith owns.

          Get Records element that shows condition requirements for OwnerId equal to John Smith's ID and How Many Records to Store set to All Records

          Then create a loop that iterates through the collection. For each item in the collection, the loop:

          1. Assigns the collection item to the loop variable.
            Loop element that shows the collection variable set to Accounts from John's Accounts
          2. Evaluates whether the account has more than 10,000 employees.
            Decision element that shows the condition requirements for the Yes outcome, where the resource is set to the Employees field on the current item in the loop, the Greater Than operator, and for Value, 10000
          3. If the account has more than 10,000 employees, assigns Madison's user ID to the OwnerId field in the loop variable.
            Assignment element that shows the variable set to the current item in the loop with the Equals operator and for Value, Madison's owner ID
          4. If the account doesn't have more than 10,000 employees, assigns Amber's user ID to the OwnerId field in the loop variable.
            Assignment element that shows the variable set to the current item in the loop with the Equals operator and for Value, Amber's owner ID
          5. Adds the loop variable's values as a new item in the collReassignedAccts collection.
            Assignment element that shows the collReassignedAccts variable with the Add operator and for Value, the current item from the loop
          6. Finally, add an Update Records element to update the accounts in collReassignedAccts with the new OwnerId after the loop finishes iterating through the collection.
            Update Records element that shows the collection variable set to the collReassignedAccts

            This section of the flow uses a single query to look up the list of accounts and a single DML statement to update those accounts. If you updated the records by setting the fields individually, you would use:

            One Update Records element to find all accounts that John owns and have more than 10,000 employees (1 query). Then update those records’ OwnerId to Madison’s Id (1 DML statement).

            One Update Records element to find all accounts that John owns and don’t have more than 10,000 employees (1 query). Then update those records’ OwnerId to Amber’s Id (1 DML statement).

           
          Loading
          Salesforce Help | Article