{"id":2524,"date":"2026-11-05T09:00:00","date_gmt":"2026-11-05T03:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/"},"modified":"2026-11-15T22:00:44","modified_gmt":"2026-11-15T16:30:44","slug":"apex-performance-profiling","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/","title":{"rendered":"Apex Performance Profiling with Limits and ApexGuru"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apex Performance Profiling means measuring where a transaction actually spends its budget rather than guessing. The platform gives you the numbers at runtime, and most slow code is fixed in one place once you can see which line costs what.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Guessing is the problem Apex Performance Profiling removes. Developers tend to blame the query, and the cost is usually a loop. Or they rewrite the loop, and the cost was a describe call made four hundred times.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-diagram-1-1024x640.png\" alt=\"Apex Performance Profiling diagram showing reproduce, capture, measure and fix\" class=\"wp-image-2522\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Caption: Measure, fix the biggest item, then measure again, because the next bottleneck is rarely the one you expected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Apex Performance Profiling Measures<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In Apex Performance Profiling four numbers matter more than the rest.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Limit<\/th><th>What it counts<\/th><th>Typical cause of trouble<\/th><\/tr><\/thead><tbody><tr><td>CPU time<\/td><td>Work your code performs<\/td><td>Nested loops and repeated describes<\/td><\/tr><tr><td>Heap size<\/td><td>Memory held at once<\/td><td>Big collections kept for the whole method<\/td><\/tr><tr><td>SOQL queries<\/td><td>Query statements issued<\/td><td>A query inside a loop<\/td><\/tr><tr><td>Query rows<\/td><td>Rows returned across all queries<\/td><td>A query with no selective filter<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">CPU time is the one that confuses people. Waiting on a callout or on the database round trip does not count, so a transaction can take ten seconds of wall clock time and use two seconds of CPU. The post on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-governor-limits-explained\/\">governor limits<\/a> lists the ceilings.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Reading the Numbers at Runtime<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Long cpuStart = Limits.getCpuTime();\nInteger heapStart = Limits.getHeapSize();\n\ncalculateFees(courses);\n\nSystem.debug(LoggingLevel.ERROR,\n    'calculateFees cpu=' + (Limits.getCpuTime() - cpuStart)\n    + ' heap=' + (Limits.getHeapSize() - heapStart)\n    + ' soql=' + Limits.getQueries()\n    + '\/' + Limits.getLimitQueries());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Two details make Apex Performance Profiling practical. Logging at error level means the line survives when the log is filtered, and taking a reading before and after a block gives you the cost of that block rather than a running total.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>What it returns<\/th><\/tr><\/thead><tbody><tr><td>Limits.getCpuTime()<\/td><td>CPU milliseconds used so far<\/td><\/tr><tr><td>Limits.getHeapSize()<\/td><td>Heap bytes in use<\/td><\/tr><tr><td>Limits.getQueries()<\/td><td>Queries issued so far<\/td><\/tr><tr><td>Limits.getQueryRows()<\/td><td>Rows returned so far<\/td><\/tr><tr><td>Limits.getDmlStatements()<\/td><td>DML statements so far<\/td><\/tr><tr><td>Limits.getLimitCpuTime()<\/td><td>The ceiling for this transaction type<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Performance Profiling with Debug Logs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For Apex Performance Profiling a debug log with everything turned up is useless, because the log fills and truncates before the interesting part. Set the categories deliberately.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Category<\/th><th>Level for profiling<\/th><\/tr><\/thead><tbody><tr><td>Apex Code<\/td><td>Debug, or Info when the log truncates<\/td><\/tr><tr><td>Apex Profiling<\/td><td>Finest<\/td><\/tr><tr><td>Database<\/td><td>Info<\/td><\/tr><tr><td>System<\/td><td>Info<\/td><\/tr><tr><td>Workflow<\/td><td>Error<\/td><\/tr><tr><td>Validation<\/td><td>Error<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The cumulative limits block at the end of the log is the first thing to read. It tells you which limit is close to its ceiling, which narrows the search before you read a single line of code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A second habit saves time. If the log truncates, raise the start point rather than the detail. Reproduce the problem with fewer records, find the pattern, then confirm at full volume.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Where ApexGuru Fits in Apex Performance Profiling<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">ApexGuru is a Salesforce tool that looks at your Apex alongside runtime information from the org and suggests specific improvements, with the line and a reason. It appears in Setup for orgs whose plan includes it, so the first step is checking your own Setup rather than assuming.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What it is good at is the pattern a human reviewer skips.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>What ApexGuru tends to surface<\/th><th>Why it matters<\/th><\/tr><\/thead><tbody><tr><td>A query inside a loop<\/td><td>The classic limit failure<\/td><\/tr><tr><td>A describe call repeated per record<\/td><td>Pure wasted CPU<\/td><\/tr><tr><td>A missing selective filter<\/td><td>Row limits and slow queries<\/td><\/tr><tr><td>Code paths that run on every save<\/td><td>Cost multiplied by volume<\/td><\/tr><tr><td>Nested loops over the same collection<\/td><td>Quadratic growth<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Treat ApexGuru as a reviewer rather than an oracle. It reports a cost and a line, and you still decide whether the fix is worth the change. Pair it with the static analysis in <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-code-analyzer-pmd\/\">Code Analyzer<\/a>, which looks at the code rather than the runtime.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Performance Profiling for CPU or Heap<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-diagram-2-1024x640.png\" alt=\"Apex Performance Profiling comparison of CPU time and heap size\" class=\"wp-image-2523\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Caption: The fix is different for each, so identify which one is near its ceiling first.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Fixing CPU Time<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Costly, since the inner loop runs for every course\nfor (Course__c c : courses) {\n    for (Enrolment__c e : enrolments) {\n        if (e.Course__c == c.Id) {\n            c.Seats_Taken__c++;\n        }\n    }\n}\n\n\/\/ Cheap, since each list is walked once\nMap&lt;Id, Integer&gt; counts = new Map&lt;Id, Integer&gt;();\nfor (Enrolment__c e : enrolments) {\n    Integer current = counts.containsKey(e.Course__c) ? counts.get(e.Course__c) : 0;\n    counts.put(e.Course__c, current + 1);\n}\nfor (Course__c c : courses) {\n    c.Seats_Taken__c = counts.containsKey(c.Id) ? counts.get(c.Id) : 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Performance Profiling makes this obvious. With 200 courses and 2,000 enrolments, the first version performs 400,000 comparisons and the second performs 2,200. That single change is the most common real fix in Apex Performance Profiling work.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Fixing Heap Size<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Query only the fields you use, since every extra field is memory per row<\/li>\n\n<li>Use a <code>for<\/code> loop over a query rather than holding the full list<\/li>\n\n<li>Clear a collection once you are finished with it<\/li>\n\n<li>Move large work into a queueable, which gets a higher heap ceiling<\/li>\n\n<li>Avoid serialising a large collection to a string, which doubles its footprint<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>for (List&lt;Enrolment__c&gt; chunk : [\n    SELECT Id, Course__c FROM Enrolment__c WHERE Status__c = 'Active'\n]) {\n    process(chunk);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The query loop is the single best heap habit, and <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/\">bulkification<\/a> covers the wider pattern it belongs to. It pulls records in chunks rather than holding every row, and it reads almost the same as the version that fails.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Apex Performance Profiling Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Performance Profiling settled an argument for us. Bright Path Tutors had an enrolment save that failed with a CPU time error whenever a bulk load ran. The team had rewritten the SOQL twice with no improvement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Profiling took twenty minutes and told a different story.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Section<\/th><th>CPU cost<\/th><\/tr><\/thead><tbody><tr><td>The query everyone blamed<\/td><td>110 ms<\/td><\/tr><tr><td>A describe call inside a loop<\/td><td>3,400 ms<\/td><\/tr><tr><td>Fee calculation nested loops<\/td><td>5,900 ms<\/td><\/tr><tr><td>Everything else<\/td><td>420 ms<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Fix<\/th><th>Result<\/th><\/tr><\/thead><tbody><tr><td>Cache the describe result in a static map<\/td><td>3,400 ms down to 15 ms<\/td><\/tr><tr><td>Replace the nested loop with a map<\/td><td>5,900 ms down to 180 ms<\/td><\/tr><tr><td>Leave the query alone<\/td><td>No change needed<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Measure<\/th><th>Before<\/th><th>After<\/th><\/tr><\/thead><tbody><tr><td>CPU time for 200 records<\/td><td>9,830 ms<\/td><td>725 ms<\/td><\/tr><tr><td>Bulk load failures<\/td><td>Every run<\/td><td>None<\/td><\/tr><tr><td>Time spent on the fix<\/td><td>20 minutes profiling, 1 hour coding<\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The Apex Performance Profiling lesson was cheap and worth repeating. Two days had already gone into rewriting the query that cost one percent of the transaction.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Apex Performance Profiling<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Mistake<\/th><th>What happens<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td>Optimising before measuring<\/td><td>Days spent on the wrong line<\/td><td>Profile first, every time<\/td><\/tr><tr><td>Testing with one record<\/td><td>The problem never appears<\/td><td>Reproduce at realistic volume<\/td><\/tr><tr><td>All log categories on finest<\/td><td>The log truncates before the cause<\/td><td>Set categories deliberately<\/td><\/tr><tr><td>Reading only the total CPU<\/td><td>No idea which section costs what<\/td><td>Take readings around each block<\/td><\/tr><tr><td>Blaming wall clock time<\/td><td>Chasing a callout that CPU ignores<\/td><td>Separate waiting from CPU<\/td><\/tr><tr><td>Describes inside loops<\/td><td>Thousands of milliseconds wasted<\/td><td>Cache them in a static<\/td><\/tr><tr><td>Holding every row in a list<\/td><td>Heap failures at volume<\/td><td>Use a query for loop<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Apex Performance Profiling<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Reproduce the problem at the volume that fails before changing anything<\/li>\n\n<li>Take limit readings around each suspect block rather than once at the end<\/li>\n\n<li>Log at error level so the measurements survive log filtering<\/li>\n\n<li>Read the cumulative limits section of the log first<\/li>\n\n<li>Cache describe results and other repeated lookups in statics<\/li>\n\n<li>Replace nested loops with maps as a reflex<\/li>\n\n<li>Fix one thing, measure again, and stop when the limit is comfortable<\/li>\n\n<li>Check whether ApexGuru is available in your org and act on what it reports<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Apex Performance Profiling Interview Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What does CPU time count?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Work your code performs. Waiting on callouts and database round trips is not counted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: Why can a slow transaction show low CPU time?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because the time went on waiting, which the CPU limit ignores.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: How do you measure the cost of one block of code?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Read the limits before and after it and subtract.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: Which method gives CPU time used so far?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Limits.getCpuTime.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: How do you find the ceiling for the current transaction?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the matching limit method, such as getLimitCpuTime.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: Why log at error level during profiling?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So the measurements survive when the log level filters out debug lines.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: Which log categories matter for profiling?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Profiling at the finest level, with Apex Code at debug, and the rest kept low.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: What do you read first in a debug log?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The cumulative limits section, which shows which limit is close to its ceiling.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: What do you do when a log truncates?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reduce the data volume or the detail, find the pattern, then confirm at full volume.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: What is the most common CPU problem in Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A loop inside a loop over two collections, which should be a map lookup.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: How much difference does that change make?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With 200 and 2,000 records, hundreds of thousands of comparisons become a few thousand.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: What is the second most common CPU problem?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A describe call or similar lookup repeated per record instead of cached.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: How do you cache a describe result?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In a static map, built once per transaction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: What causes heap failures?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Holding large collections in memory, often with more fields than the code uses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: What is the best heap habit?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A for loop directly over a query, which processes records in chunks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: Does asynchronous Apex get different limits?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. CPU and heap ceilings are higher in asynchronous contexts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: Is moving work to a queueable a performance fix?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It raises the ceiling, which buys room, but inefficient code is still inefficient.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: What is ApexGuru?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Salesforce tool that reviews Apex with runtime information and suggests specific improvements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: Where do you find it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Setup, for orgs whose plan includes it, so check your own org rather than assuming.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: What does it tend to surface?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Queries in loops, repeated describes, missing selective filters and nested loops.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: How does it differ from Code Analyzer?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Code Analyzer is static analysis of the code, while ApexGuru also considers how the code runs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22: Should you accept every suggestion?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Treat it as a reviewer and judge whether each fix is worth the change.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q23: Scenario: a trigger fails on CPU at 200 records but passes at 50. What do you suspect?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Work that grows faster than the record count, which usually means nested loops.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q24: Scenario: the query was rewritten twice with no gain. What went wrong?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nobody profiled, so the real cost was somewhere else.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q25: Scenario: heap fails only on the largest accounts. Why?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A collection sized by related records, held in memory rather than chunked.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q26: Scenario: the log has no cumulative limits section. What happened?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The log truncated, so lower the detail or the volume and capture it again.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q27: How do you prove a fix worked?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Measure the same transaction again at the same volume and compare the numbers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q28: When do you stop optimising?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When the limit usage is comfortable at realistic volume, not when the code looks clever.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q29: What is the one habit that makes profiling pay off?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Measure before you change anything, and measure again after.<\/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:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexref.meta\/apexref\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Reference Guide<\/a><\/li>\n\n<li><a href=\"https:\/\/help.salesforce.com\/s\/articleView?id=platform.code_add_users_debug_log.htm&amp;type=5\" target=\"_blank\" rel=\"noopener noreferrer\">Debug Logs in Salesforce Help<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Next<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, read <a href=\"https:\/\/swapnilzambare.com\/blog\/appexchange-security-review\/\">AppExchange Security Review and Managed Packages<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apex Performance Profiling means measuring where a transaction actually spends its budget rather than guessing. The platform gives you the numbers at runtime, and&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2521,"comment_status":"closed","ping_status":"closed","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,243],"tags":[68,98,109],"swapz_series":[],"class_list":["post-2524","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","category-salesforce-developer","category-testing-debugging","tag-advanced","tag-apex","tag-governor-limits"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apex Performance Profiling with ApexGuru Guide<\/title>\n<meta name=\"description\" content=\"Apex Performance Profiling finds the CPU and heap hot spots before users do. Learn to read limits at runtime, use debug logs properly and act on ApexGuru.\" \/>\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-performance-profiling\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex Performance Profiling with ApexGuru Guide\" \/>\n<meta property=\"og:description\" content=\"Apex Performance Profiling finds the CPU and heap hot spots before users do. Learn to read limits at runtime, use debug logs properly and act on ApexGuru.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-05T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-15T16:30:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-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-performance-profiling\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-performance-profiling\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"Apex Performance Profiling with Limits and ApexGuru\",\"datePublished\":\"2026-11-05T03:30:00+00:00\",\"dateModified\":\"2026-11-15T16:30:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-performance-profiling\\\/\"},\"wordCount\":1749,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-performance-profiling\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-performance-profiling-featured.png\",\"keywords\":[\"Advanced\",\"Apex\",\"Governor Limits\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\",\"Testing and Debugging\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-performance-profiling\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-performance-profiling\\\/\",\"name\":\"Apex Performance Profiling with ApexGuru Guide\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-performance-profiling\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-performance-profiling\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-performance-profiling-featured.png\",\"datePublished\":\"2026-11-05T03:30:00+00:00\",\"dateModified\":\"2026-11-15T16:30:44+00:00\",\"description\":\"Apex Performance Profiling finds the CPU and heap hot spots before users do. Learn to read limits at runtime, use debug logs properly and act on ApexGuru.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-performance-profiling\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-performance-profiling\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-performance-profiling\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-performance-profiling-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-performance-profiling-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex Performance Profiling featured image showing CPU and heap measurements across a transaction\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-performance-profiling\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex Performance Profiling with Limits and ApexGuru\"}]},{\"@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\\\/10b09224c8bcc562716e86789427592a\",\"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 Performance Profiling with ApexGuru Guide","description":"Apex Performance Profiling finds the CPU and heap hot spots before users do. Learn to read limits at runtime, use debug logs properly and act on ApexGuru.","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-performance-profiling\/","og_locale":"en_US","og_type":"article","og_title":"Apex Performance Profiling with ApexGuru Guide","og_description":"Apex Performance Profiling finds the CPU and heap hot spots before users do. Learn to read limits at runtime, use debug logs properly and act on ApexGuru.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-11-05T03:30:00+00:00","article_modified_time":"2026-11-15T16:30:44+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-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-performance-profiling\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"Apex Performance Profiling with Limits and ApexGuru","datePublished":"2026-11-05T03:30:00+00:00","dateModified":"2026-11-15T16:30:44+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/"},"wordCount":1749,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-featured.png","keywords":["Advanced","Apex","Governor Limits"],"articleSection":["Salesforce","Salesforce Developer","Testing and Debugging"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/","name":"Apex Performance Profiling with ApexGuru Guide","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-featured.png","datePublished":"2026-11-05T03:30:00+00:00","dateModified":"2026-11-15T16:30:44+00:00","description":"Apex Performance Profiling finds the CPU and heap hot spots before users do. Learn to read limits at runtime, use debug logs properly and act on ApexGuru.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-performance-profiling-featured.png","width":2400,"height":1260,"caption":"Apex Performance Profiling featured image showing CPU and heap measurements across a transaction"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-performance-profiling\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apex Performance Profiling with Limits and ApexGuru"}]},{"@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\/10b09224c8bcc562716e86789427592a","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\/2524","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=2524"}],"version-history":[{"count":2,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2524\/revisions"}],"predecessor-version":[{"id":3408,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2524\/revisions\/3408"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/2521"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=2524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=2524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=2524"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=2524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}