Salesforce Governor Limits – Understanding Limits in Flow with Data Import Wizard

governorlimitsvisual-workflow

I am trying to learn about governor limits in salesforce, specifically in the context of salesforce flows. Here is the context: I have written a flow that runs 'on insert' for a given object (contacts). Every time a new record is inserted, I am performing a check to see if there is an account record with a matching email address (custom field) as the email address on the contact. In essence, this is a lookup relationship, but is meant to automatically find the relationship. It then updates the new contact to associate the related account with it.

However, I am building this with the idea that a user will be uploading many (possibly thousands) of contact records with the data import wizard. I have concerns that I will reach governor limits in my flow for such a large import. However, when testing my flow after uploading a large file of test data contacts, I do not appear to hit any governor limits. The specific limit I am thinking of is where a transaction is limited to 150 DML statements. I understand that salesforce performs bulkification to combine limits for large transaction (like when uploading a lot of records) and that the governor limits apply to batches of 200 records. If this is the case, since every records in the batch of 200 is updating the contact, I would expect to have errors when uploading my large contact file (batched to 200 records, every records would contribute a limit to the 150 limit and it would fail before completing the first batch). However, I am not getting an error, so it appears that I don't understand something correctly, either how the bulkification / batching process works, or specifically regarding the DML governor limits.

Can anyone explain what I am missing here? Here is a snapshot of my flow for context. Please note that I am calling this flow from a simple flow that has the 'on insert' trigger. Thanks!

enter image description here

Best Answer

The Data Import Wizard processes records 200 at a time, using the Bulk API. That means that every 200 records get their own governor limits, no matter how many records you import, up to the maximum limit of however many records you're allowed to import.

The flow behavior is described in Flow Bulkification in Transactions. An Interview is created for each record in a transaction (up to 200 records), and each Interview will run until it reaches a bulkified element (Get Records, Update Records, etc), Pause element, or End element. Once every Interview reaches one of these states, those that are in a bulkified state will execute the element once using all of the data. That means that the bulkified element will use at most one resource (one DML for a DML element, one SOQL for a Get element, etc) per invocation. Paused Flows are saved and set aside, and interviews that have hit the End element will no longer be processed. All remaining Interviews will be run until they reach one of those conditions again, and the cycle repeats, until there are no more Interviews to execute.

Transaction governor limits are reset with every transaction, so from an API perspective, every up to 200 records get their own governor limits, no matter how many records you're uploading "at once." You do need to be careful in Apex code, because your transactions will be batched into groups of 200, and every 200 records will consume additional limits. For example, if you create a list of 1000 records, you'll use five times the governor limit than you would if you were using an API, since the governor limits are cumulative from the beginning to the end of a transaction; DML operations are subtransactions in the context of calling an Apex method, such as a webservice call, Remote Action, etc.

Related Topic