Governor Limits Demystified: How Our Developers Write Efficient Apex Code That Scales
Learn the proven 6-step methodology Technolance developers use to write Salesforce Apex code that handles thousands of records without hitting governor limits. From bulk-friendly coding patterns to smart collection usage and background job processing, discover how to transform failing code into scalable solutions that grow with your business.

Today we are going to show you how our Salesforce developers at Technolance write smart Apex code that avoids hitting governor limits, even when working with thousands of records.
We have worked with many clients who struggled with governor limits. From hitting SOQL limits to CPU timeouts, these problems used to slow them down. With a few key techniques, we helped them fix their code and grow with confidence.
In this case study, we will take you through the exact steps our team follows every day at Technolance.
Learn From The Developer Team
Our Salesforce team works with global clients across many industries. Some of these clients come to us with Apex code that works well for small data loads but fails when more records are added.
One thing that’s common in what our clients tell us is that "Everything breaks when we run big data updates." That is when our team stepped in. We reviewed their code, spotted the issues, and rewrote it to follow governor limit best practices.
Now, the same client can run large-scale processes smoothly. They continue to grow without running into system errors.
Let us walk you through the process our Technolance developers use to write safe and efficientApex code.
How We Write Apex Code That Avoids Limits
Here is the simple 4-step approach we follow at Technolance:
Step 1: Write Bulk-Friendly Code
We treat everyApex class and trigger like it might need to handle 200 records at once. That is because it often will.
This is what we do:
· We avoid using SOQL or DML statements inside loops
· We use Trigger.new and Trigger.old as full lists, not single records
· We always test our logic with large record sets in our test classes
This approach keeps the code ready for growth and large data loads.
Step 2: Use Maps and Sets the Smart Way
Collections are key to efficient coding. They help us reduce system load and speed upprocessing.
Here is how we use them:
· Maps store records by ID for quick lookups
· Sets help manage unique values
· Queries are combined with collections to keep logic clean and fast
Just by using collections well, we have helped several clients reduce the number of queries and improve performance.
Step 3: Track Limits While Coding
Salesforce offers the Limits class to help track governor limits in real time. Our developers use it during both development and testing.
Here is how it helps:
· We use Limits.getQueries andLimits.getDMLStatements to track how many SOQL calls are being made
· We monitor CPU time closely using Limits.get Cpu Time during test runs
· We log this data in lower environments to catch issues before they go live
This lets us catch problems early and plan for high-usage scenarios.
Step 4: Move Big Tasks to Background Jobs
Some tasks take longer than a normal process allows. That is when we move them to run in the background.
Here is what works best:
· Queue able Apex handles medium-sized background jobs
· Batch Apex is great for large data processing
· Our triggers are kept clean and hand off heavy work to background methods
This way, users get a fast and smooth experience while big jobs run safely in the background.
Step 5: Use Custom Settings to Control Trigger Behavior
Sometimes, you do not need to run your trigger logic in every environment or during certain operations. That is where configuration comes in handy.
At Technolance, we:
· Use Custom Metadata Types to turn trigger logic on or off
· Control execution through environment-level flags
· Avoid hardcoded logic that limits flexibility
This makes our code more flexible and easier to manage without changing anything in production.
Step 6: Test Beyond Code Coverage
We believe that passing tests is not enough. Your tests should simulate real scenarios thatpush the limits.
Our approach:
· Write tests with over 200 records to simulate bulk operations
· Use Test.startTest and Test.stopTest to isolate and measure performance
· Include edge cases like empty records, duplicates, and invalid inputs
This ensures the code performs well not just in theory but in real-world use cases too.
Conclusion
That is how our developers at Technolance build Apex code that handles scale without ever crossing governor limits. The best part is that you can do it too. Just follow the same four steps and test your logic at scale.
If you found this helpful, share it with your team or a fellow Salesforce developer.
👉 Need help dealing with governor limit issues or want to improve your Apex quality or reviewing your Salesforce code? Connect with the Technolance team.
More stories of success
Explore how Innovia has helped other businesses achieve their goals through innovative strategies and impactful solutions.
Ready to elevate your business?
Connect with our expert team today and discover how we can turn your digital challenges into opportunities for growth.
Stay ahead in the digital world
Get the latest insights, case studies, trends, and strategies delivered straight to your inbox.