From a435a2c8ab4ea4ddc1c70ccd461512257b3334df Mon Sep 17 00:00:00 2001 From: Watana Date: Mon, 26 Jan 2026 12:11:32 +1300 Subject: [PATCH] Update ForAll + Patch examples --- .../coding-guidelines/code-optimization.md | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/powerapps-docs/guidance/coding-guidelines/code-optimization.md b/powerapps-docs/guidance/coding-guidelines/code-optimization.md index 348468a8f5..706141554d 100644 --- a/powerapps-docs/guidance/coding-guidelines/code-optimization.md +++ b/powerapps-docs/guidance/coding-guidelines/code-optimization.md @@ -476,23 +476,23 @@ ClearCollect(FollowUpMeetingAttendees.ForAll(ForAll(Distinct(AttendeesList.Email ForAll + Patch can be one approach to Batch update the database. However, be careful in using the order of For All and Patch. -Following function: +The following Patch() inside a ForAll() loop creates multiple individual requests that execute one after another in sequence, which results in slow performance. ```powerappsfl -Patch(SampleFoodSalesData, ForAll(colSampleFoodSales, - { - demoName:"fromCanvas2" - }) +ForAll( colSampleFoodSales, + Patch( SampleFoodSalesData, + { demoName: "test" } + ) ); ``` -Performs better than: +Instead of patching individual records inside a loop, pass the entire collection to Patch() in a single operation. These updates happen in parallel, significantly improve performance. ```powerappsfl -ForAll(colSampleFoodSales, Patch(SampleFoodSalesData, - { - demoName:"test" - }) +Patch( SampleFoodSalesData, + ForAll( colSampleFoodSales, + { demoName: "fromCanvas2" } + ) ); ```