How to update “N” records in Flow

 If you are implementing business logic through Salesforce’s flow, you might need to loop through a list of records to do some manipulation. This is a very basic requirement. If you ever need to query records from Salesforce (let’s say all accounts where the billing country is India), it is very easy to do in SOQL and Get Records flow elements. But things will become a little tricky when the requirement says “Fetch first 5 accounts based on the created date where the billing country in India”. It is definitely very easy in SOQL with the limit statement, but in Get Records flow element, there is no way to (as of Winter’21 release) limit the record.To overcome this situation, we can implement the counter mechanism which will basically make sure that when the # of loop iteration is greater than 5 (because we just need the first 5 accounts), the flow will not perform any business logic.Here is the overall flow -Here as you can see for each loop iteration, we are incrementing the counter value by 1 and then checking whether the new value is greater than 5 or not. Based on that decision element, either we are updating the account’s rating i.e. performing business logic or ignoring the business logic execution. This flow solution is definitely making sure that only for the first 5 records the business logic...

Read More