Overview
This rule flags Apex code where a method annotated with @future is called inside a loop. While @future methods are designed for asynchronous execution, invoking them in a loop can quickly exhaust Salesforce governor limits and introduce execution unpredictability.
Code Reviews classifies this as an Error because it severely impacts system performance, reliability, and scalability especially in bulk processing scenarios.
Why This Matters
Calling @future methods inside loops can:
Exceed the asynchronous call limit (only 50
@futurecalls allowed per transaction)Cause runtime exceptions that may disrupt business processes
Lead to race conditions or inconsistent data states
Violate Salesforce best practices for bulk-safe asynchronous processing
This issue is especially critical in triggers, where processing multiple records is common.
β
What Triggers This Rule
Code Reviews flags any Apex code where:
A
@futuremethod is directly invoked within afor,while, ordo-whileloopEach iteration of the loop potentially triggers a separate asynchronous call
Recommended Approach
Aggregate data outside the loop, then make a single @future call that handles all records in bulk.
Summary
Never call @future methods inside loops. Instead, collect all needed data first and invoke the method once with a bulk-safe parameter. Code Reviews flags this as an Error to help teams avoid governor limit violations and maintain scalable asynchronous logic.
