{"id":1531,"date":"2026-09-06T17:00:00","date_gmt":"2026-09-06T11:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/"},"modified":"2026-09-06T17:00:00","modified_gmt":"2026-09-06T11:30:00","slug":"apex-bulkification-best-practices","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/","title":{"rendered":"Apex Bulkification: Write Code That Handles 200 Records"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apex Bulkification means writing code that works just as well for 200 records as it does for one. Triggers, classes and flows can receive many records at once from Data Loader, the API or a mass update. Code that handles one record at a time works in a demo and fails in production.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, you will learn the four bulkification patterns, fix a real non-bulk trigger step by step, and test it with 200 records. This is the most important habit in Apex. It builds directly on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-governor-limits-explained\/\">Apex Governor Limits<\/a>, <a href=\"https:\/\/swapnilzambare.com\/blog\/before-vs-after-triggers-apex\/\">before vs after triggers<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-collections-list-set-map\/\">Apex collections: List, Set and Map<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Apex Bulkification?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Bulkification is the practice of processing records as a group. Instead of running a query or DML statement for each record, bulk code collects what it needs, runs one query per object, processes everything in memory and saves with one DML statement per object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a school canteen at lunch time. A bad system cooks one plate, walks it to one student, then goes back to cook the next. A good system cooks a big pot, serves the whole line, then washes up once. Bulk code is the big pot.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Apex Bulkification Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce sends records to triggers in chunks of up to 200. Here is why Apex Bulkification matters at Bright Path Tutors.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, the training team imports 1,000 enrolments every Monday with Data Loader.<\/li>\n\n<li>Also, a fee change on a course updates 300 enrolments through a flow.<\/li>\n\n<li>Next, an integration sends enrolments in batches of 200 through the API.<\/li>\n\n<li>A mass update from a list view changes 50 courses in one click.<\/li>\n\n<li>Finally, non-bulk code hits governor limits and fails the whole batch.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So every trigger and class must assume many records, not one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Apex Bulkification Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Bulkification follows four steps. First, loop once over the records and collect the Ids or values you need into sets. Next, run one query per object using those sets. Then put the results into maps for fast lookups. After that, loop again and do the work in memory, adding changed records to a list. Finally, run one DML statement per object on that list.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-1-1024x640.png\" alt=\"Apex Bulkification diagram showing collect, query once, map, work, collect changes and DML once\" class=\"wp-image-1529\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-1-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-1-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">The four-step bulk pattern for triggers.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Collect with Sets<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A set stores unique values, such as course Ids. Even if 200 enrolments share 3 courses, the set holds just 3 Ids.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Query Once with IN<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">One query with <code>WHERE Id IN :courseIds<\/code> replaces hundreds of single-record queries.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Look Up with Maps<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A map gives instant access to a record by Id. So inside the loop, <code>courseMap.get(e.Course__c)<\/code> replaces a query.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Save Once with Lists<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add every changed record to one list, then run one update. This uses one DML statement, however many records change.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Four Bulkification Patterns<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below summarises the patterns and the limits they protect.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Pattern<\/th><th>Code shape<\/th><th>Protects<\/th><\/tr><\/thead><tbody><tr><td>Collect with a set<\/td><td>ids.add(r.Lookup__c)<\/td><td>Query count<\/td><\/tr><tr><td>Query once<\/td><td>WHERE Id IN :ids<\/td><td>100 SOQL limit<\/td><\/tr><tr><td>Look up with a map<\/td><td>map.get(r.Lookup__c)<\/td><td>CPU time and queries<\/td><\/tr><tr><td>Save once<\/td><td>update changedList<\/td><td>150 DML limit<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Non-Bulk Code vs Apex Bulkification<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares the two styles.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Non-bulk code<\/th><th>Bulk code<\/th><\/tr><\/thead><tbody><tr><td>Queries for 200 records<\/td><td>200<\/td><td>1<\/td><\/tr><tr><td>DML statements for 200 records<\/td><td>200<\/td><td>1<\/td><\/tr><tr><td>Works with Data Loader<\/td><td>No, fails at 101 queries<\/td><td>Yes<\/td><\/tr><tr><td>Speed<\/td><td>Slow<\/td><td>Fast<\/td><\/tr><tr><td>Typical sign<\/td><td>Query or DML inside a for loop<\/td><td>Sets, maps and lists<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is not a real choice. Always write bulk code, even when you expect only one record today.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-2-1024x640.png\" alt=\"Apex Bulkification diagram comparing non-bulk code and bulk code\" class=\"wp-image-1530\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-2-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-2-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Non-bulk code vs bulk code.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Apex Bulkification Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s fix a real trigger at Bright Path Tutors. When a course fee changes, every active enrolment on that course must get the new Amount Due.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: The Non-Bulk Version<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ BAD: query and DML inside the loop\ntrigger CourseTrigger on Course__c (after update) {\n    for (Course__c c : Trigger.new) {\n        if (c.Fee__c != Trigger.oldMap.get(c.Id).Fee__c) {\n            List&lt;Enrolment__c&gt; rows = [SELECT Id FROM Enrolment__c\n                WHERE Course__c = :c.Id AND Status__c = 'Active'];\n            for (Enrolment__c e : rows) {\n                e.Amount_Due__c = c.Fee__c;\n            }\n            update rows;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This works when one course changes. However, a mass update of 120 courses runs 120 queries and 120 updates. It fails at query number 101.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: The Bulk Version<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>trigger CourseTrigger on Course__c (after update) {\n\n    \/\/ 1. Collect courses whose fee changed\n    Map&lt;Id, Decimal&gt; newFeeByCourse = new Map&lt;Id, Decimal&gt;();\n    for (Course__c c : Trigger.new) {\n        if (c.Fee__c != Trigger.oldMap.get(c.Id).Fee__c) {\n            newFeeByCourse.put(c.Id, c.Fee__c);\n        }\n    }\n    if (newFeeByCourse.isEmpty()) {\n        return;\n    }\n\n    \/\/ 2. One query for all affected enrolments\n    List&lt;Enrolment__c&gt; toUpdate = new List&lt;Enrolment__c&gt;();\n    for (Enrolment__c e : [SELECT Id, Course__c FROM Enrolment__c\n                           WHERE Course__c IN :newFeeByCourse.keySet()\n                           AND Status__c = 'Active']) {\n        \/\/ 3. Work in memory with the map\n        e.Amount_Due__c = newFeeByCourse.get(e.Course__c);\n        toUpdate.add(e);\n    }\n\n    \/\/ 4. One DML statement\n    update toUpdate;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first loop collects only changed courses and their new fees in a map. If nothing changed, the trigger stops early. Then one query loads all active enrolments for those courses. The map gives each enrolment its new fee, and one update saves them all.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Test with 200 Records<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>@IsTest\nprivate class CourseTriggerTest {\n    @IsTest\n    static void updatesEnrolmentsInBulk() {\n        List&lt;Course__c&gt; courses = new List&lt;Course__c&gt;();\n        for (Integer i = 0; i &lt; 200; i++) {\n            courses.add(new Course__c(Name = 'Course ' + i, Fee__c = 1000));\n        }\n        insert courses;\n\n        List&lt;Enrolment__c&gt; rows = new List&lt;Enrolment__c&gt;();\n        for (Course__c c : courses) {\n            rows.add(new Enrolment__c(Course__c = c.Id, Status__c = 'Active'));\n        }\n        insert rows;\n\n        for (Course__c c : courses) { c.Fee__c = 2000; }\n        Test.startTest();\n        update courses;\n        Test.stopTest();\n\n        Integer updated = [SELECT COUNT() FROM Enrolment__c WHERE Amount_Due__c = 2000];\n        System.assertEquals(200, updated, 'All enrolments should have the new fee');\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The test inserts 200 courses and 200 enrolments, then changes every fee in one update. If the trigger were not bulk-safe, it would fail with a limit error. We will cover test classes fully in Level 5.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Read the Result<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In the Developer Console Tests tab, the run shows a pass like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CourseTriggerTest.updatesEnrolmentsInBulk    Pass<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Bulkification Beyond Triggers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Bulkification applies everywhere, not only in triggers. Invocable methods called from flows receive a list of inputs. Batch Apex receives a list in each execute call. Even a simple utility method should accept a list rather than one record. So design every method to take collections.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Avoiding Nested Loops<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Nested loops over two large lists can hit the CPU time limit. For example, comparing 200 enrolments with 2,000 courses in two loops means 400,000 checks. A map lookup turns that into 200 checks. So whenever you see a loop inside a loop, ask if a map would work instead.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Apex Bulkification<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Writing queries or DML inside for loops.<\/li>\n\n<li>Using Trigger.new[0] and ignoring the other records.<\/li>\n\n<li>Testing with one record only.<\/li>\n\n<li>Using nested loops instead of maps.<\/li>\n\n<li>Updating records that did not change, which wastes DML rows.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Apex Bulkification<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Collect Ids in sets and query once with IN.<\/li>\n\n<li>Use maps for lookups inside loops.<\/li>\n\n<li>Save changes with one DML statement per object.<\/li>\n\n<li>Process only records whose relevant fields changed.<\/li>\n\n<li>Always test with at least 200 records.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Write a bulk after insert trigger on Enrolment__c that adds 1 to each course&#8217;s Seats_Booked__c field. Hint: count new enrolments per course in a Map of Id to Integer, query those courses once, then update them in one statement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Interview Questions on Apex Bulkification<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Bulkification is the most tested Apex skill in coding rounds. Here are the 21 questions asked most about Apex Bulkification.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Questions on Apex Bulkification<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What is bulkification?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It means writing code that handles many records at once, using one query and one DML statement per object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: Why is bulkification needed?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Triggers and methods can receive up to 200 records at once. So code that queries per record hits governor limits.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: How many records does a trigger receive at once?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Up to 200 records per chunk. Larger saves are split into several chunks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: Which collection removes duplicate Ids?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Set, because it stores only unique values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: Why use a Map in bulk code?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It lets you find a record by Id instantly, without another query.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: What is the clearest sign of non-bulk code?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A SOQL query or DML statement inside a for loop.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: How do you save many records with one DML statement?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add them to a list and run one insert or update on the list.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code and Scenario Questions on Apex Bulkification<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: How do you get parent data for 200 child records?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Collect parent Ids in a set, query the parents once with IN, and store them in a map.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: How do you skip records that did not change?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Compare each record with Trigger.oldMap and only process records whose fields changed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: How do you test bulkification?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Write a test that inserts or updates at least 200 records in one DML statement and asserts the results.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: What error appears when code is not bulkified?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Usually System.LimitException: Too many SOQL queries: 101, or Too many DML statements: 151.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: How do you count child records per parent in bulk?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use an aggregate query with GROUP BY on the parent Id, or a Map of Id to Integer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: Should a utility method accept one record or a list?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A list. It can then handle one or many records with the same code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: How do you bulkify an invocable method for flows?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Accept a List of inputs and process them together, because flows send many interviews at once.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Questions on Apex Bulkification<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: How do nested loops affect limits?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They multiply the work and can hit the CPU time limit. Maps usually replace the inner loop.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: How does bulkification help with the 10,000 DML row limit?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It does not raise the limit. However, skipping unchanged records reduces the rows you use.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: How would you handle 50,000 records?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use Batch Apex, which splits records into smaller transactions, each processed in bulk.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: What is a SOQL for loop and why use it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It loops directly over a query and fetches records in chunks, which saves heap memory for large results.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: Can a bulk trigger still fail for one bad record?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Plain DML fails the whole list. Database methods with allOrNone false can save the rest.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: How do you avoid running the same query in many classes in one transaction?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cache results in a static map, so later calls reuse the data instead of querying again.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: Is bulkification only for triggers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. It applies to all Apex, including flows calling Apex, batch jobs, services and integrations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/trailhead.salesforce.com\/content\/learn\/modules\/apex_triggers\/apex_triggers_bulk\" target=\"_blank\" rel=\"noopener noreferrer\">Bulk Apex Triggers (Trailhead)<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_gov_limits.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Execution Governors and Limits (Apex Developer Guide)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Apex Bulkification means handling many records together.<\/li>\n\n<li>Collect with sets, query once, look up with maps and save once.<\/li>\n\n<li>Never put SOQL or DML inside loops.<\/li>\n\n<li>Process only records that changed.<\/li>\n\n<li>Test every trigger with at least 200 records.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Bulk code is easier to manage when it lives in classes. Next, read our guide to the <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-trigger-handler-pattern\/\">Apex trigger handler pattern<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apex Bulkification means writing code that works just as well for 200 records as it does for one. Triggers, classes and flows can receive&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1528,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[8,96],"tags":[98,109,26,91,7,97],"swapz_series":[],"class_list":["post-1531","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","category-salesforce-developer","tag-apex","tag-governor-limits","tag-intermediate","tag-interview-questions","tag-salesforce","tag-salesforce-developer"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apex Bulkification: Best Practices with Examples<\/title>\n<meta name=\"description\" content=\"Apex Bulkification explained simply: sets, maps, one query and one DML per object, bulk tests with 200 records, before and after code and 21 interview Q&amp;A.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex Bulkification: Best Practices with Examples\" \/>\n<meta property=\"og:description\" content=\"Apex Bulkification explained simply: sets, maps, one query and one DML per object, bulk tests with 200 records, before and after code and 21 interview Q&amp;A.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-06T11:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\"},\"headline\":\"Apex Bulkification: Write Code That Handles 200 Records\",\"datePublished\":\"2026-09-06T11:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/\"},\"wordCount\":1590,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-bulkification-best-practices-featured.png\",\"keywords\":[\"Apex\",\"Governor Limits\",\"Intermediate\",\"Interview Questions\",\"Salesforce\",\"Salesforce Developer\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/\",\"name\":\"Apex Bulkification: Best Practices with Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-bulkification-best-practices-featured.png\",\"datePublished\":\"2026-09-06T11:30:00+00:00\",\"description\":\"Apex Bulkification explained simply: sets, maps, one query and one DML per object, bulk tests with 200 records, before and after code and 21 interview Q&A.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-bulkification-best-practices-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-bulkification-best-practices-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex Bulkification featured image: title card with an Apex code example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-bulkification-best-practices\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex Bulkification: Write Code That Handles 200 Records\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apex Bulkification: Best Practices with Examples","description":"Apex Bulkification explained simply: sets, maps, one query and one DML per object, bulk tests with 200 records, before and after code and 21 interview Q&A.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/","og_locale":"en_US","og_type":"article","og_title":"Apex Bulkification: Best Practices with Examples","og_description":"Apex Bulkification explained simply: sets, maps, one query and one DML per object, bulk tests with 200 records, before and after code and 21 interview Q&A.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-06T11:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a"},"headline":"Apex Bulkification: Write Code That Handles 200 Records","datePublished":"2026-09-06T11:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/"},"wordCount":1590,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-featured.png","keywords":["Apex","Governor Limits","Intermediate","Interview Questions","Salesforce","Salesforce Developer"],"articleSection":["Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/","name":"Apex Bulkification: Best Practices with Examples","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-featured.png","datePublished":"2026-09-06T11:30:00+00:00","description":"Apex Bulkification explained simply: sets, maps, one query and one DML per object, bulk tests with 200 records, before and after code and 21 interview Q&A.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-bulkification-best-practices-featured.png","width":2400,"height":1260,"caption":"Apex Bulkification featured image: title card with an Apex code example"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apex Bulkification: Write Code That Handles 200 Records"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1531"}],"version-history":[{"count":0,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1531\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1528"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1531"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}