Avoid Governor Limit in Salesforce Flow by Checking the Limit before Hitting the Limit

Munawirrahman
4 min readNov 26, 2023

--

Hi Folks!

As a Salesforce flow developer, getting flow execution error may be one of your biggest nightmare and you may need to spend so much hours debugging about what’s wrong with your flow, look up the error message, and turns out your error happened because of Governour Limit. You may already know as a Salesforce professional, one of your biggest job is to avoid Governor Limit and making sure that your implementation is not violating any of those limits.

Debugging flow error is not an easy task, because sometimes it does not show the obvious reason your flow execution is breaking. For example, you may already bulkified your records update transaction, but what if that DML triggers another record triggered or Apex Trigger and consume another limits? well, I think we all been there before.

In Apex, you can easily check the number of limits you consumed vs the total limits you have utilizing Limits Class. Knowing the remaining of limits you have in runtime will surely help you to avoid those governor limit and have a fallback plan in case that happened. So in this article, I would like to show you a new extension that I made to help you accessing those limits in Flow with Invocable Check Limit.

Invocable Check Limit

Image 01 Invocable Check Limit

Invocable Check Limit is an invocable method (an apex function that you can access in flow) that can help you to access the governour limit of your current runtime flow transaction. It will return the total limit, total issued, and ratio of issued to limit for a specified limit type.

Input Attribute

  1. Limit Name / Limit Type
    In this attribute, you need to define the type of the limit you want to access. The list of the limit type you can select is being provided as a picklist. There are 16 types of limit you can access within this function, all of those limits are the limit that I can access from this Limit Class and has not been deprecated yet.
    Type : Text / String in a picklist format
    Example : queries (labeled as SOQL Queries)

Output Attributes

  1. Total Limit Issued
    This output shows you the number of resource you already consumed within your current transaction.
    Type : Number
    Example : 20
  2. Total Limit
    This output shows you the number of resource you can consume within your current transaction. Remember that the number of limit you have may be different when you run your flow synchronously and asynchronously.
    Type : Number
    Example : 100
  3. Ratio Issued to Limit
    This output shows you the limit issued / your total limit. For example if you have 100 SOQL / GET Records Limit and you already consumed 20. It will show 0,20 (20 SOQL issued / 100 SOQL limits)
    Type : Number (Decimal)
    Example : 0,20

When to Use this (use cases I can think of)

  1. When you get an error when running flow and the error is due to governour limit, you can try to use this limit checker to check which path consume more limit
  2. When you trying to weigh efficiency between 2 or more approaches, you can use this limit (like checking cpu time or heap size) and go with the approach which consume less resources
  3. When you update records that trigger another flow or apex trigger, using this apex action, you will be able to see how much resources your action been consuming. Knowing this will help you to add a fallback mechanism in case your transaction almost reached the limit.
Image 02 Sample Action
Image03 Sample Get SOQL Limit
Image04 Debug Sample

Installation

Install Production
Install Sandbox
Source Code

There you go, now you have a new action that make your flow functioanlity closer to Apex. Please clap if you think this is useful and comment if you have any feedbacks or questions. Thank you.

--

--