Canvas Apps Performance

B – Batch updates using ForAll or not – Which is better?

Batch/bulk updates

Introduction

Updating existing records and creating new records is one of the most commonly used functionality in Power Apps. Patch function is used to perform these functions. It is also very common to update or create records in bulk or batch. We will look at two different ways to do this and why one is better than the other.

Batch updates using ForAll

Consider a collection of Accounts. And let's say you want to update the phone number of all accounts to 5678. One way to do that is to use the ForAll function with the following code:

ForAll(
    colAccounts,
    Patch(
        Accounts,
        ThisRecord,
        {'Other Phone': "5678"}
    )
)

Batch updates without ForAll

The other method is to first update the collection with the phone number. Then do these updates in batch using just the Patch function with the following code:

ForAll(
    colAccounts,
    Patch(
        colAccountUpdates,
        ThisRecord,
        {'Other Phone': "1234"}
    )
);
Patch(
    Accounts,
    colAccountUpdates
)

Comparison

Now let's compare the two by visually seeing how the two work. First, we will update the phone number of all accounts to 5678 using ForAll:

Batch updates using ForAll
Batch updates using ForAll

Second, we will update the phone number of all accounts to 1234 using just Patch, without using ForAll:

Batch updates using Patch without ForAll
Batch updates using Patch without ForAll

As you can see, the ForAll is super slow because it updates one record at a time. You can also note for how long the button remains disable. Now, if you look at the 2nd video, it is super quick. All accounts get updated in one go.

Thus, it is recommended to use the 2nd approach to perform batch updates.

Stay tuned for the remaining 24 tips!

Recent articles

  1. A - Accordion gallery - How to make one in Power Apps
  2. Know if a user is using Desktop or Mobile
  3. How to default a SharePoint person column

Leave a Reply