{"id":1244,"date":"2026-09-04T09:00:00","date_gmt":"2026-09-04T03:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/"},"modified":"2026-09-04T09:00:00","modified_gmt":"2026-09-04T03:30:00","slug":"static-vs-instance-apex","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/","title":{"rendered":"Static vs Instance Members in Apex Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Static vs Instance is one of the first design choices you make for every variable and method in Apex. A static member belongs to the class itself, so there is only one copy. An instance member belongs to each object, so every object has its own copy. Getting this right avoids strange bugs, and it is a favourite interview question.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You have already seen both kinds. The <code>FeeCalculator<\/code> class from <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-methods-parameters-return-types\/\">Apex methods<\/a> used static methods. The <code>CourseBatch<\/code> class from <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/\">Apex classes and objects<\/a> used instance methods. In <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-access-modifiers\/\">Apex access modifiers<\/a>, you saw that <code>protected<\/code> only works on instance members. Now we will put the two side by side.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Does Static vs Instance Mean?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You mark a static variable or method with the <code>static<\/code> keyword. It lives on the class, and you use it through the class name, such as <code>FeeCalculator.finalFee(6000)<\/code>. You do not need to create an object first.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An instance variable or method has no <code>static<\/code> keyword. It lives on each object. So you must create an object with <code>new<\/code> before you can use it, such as <code>morningBatch.enrol()<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a simple picture. Think of a school. The school&#8217;s phone number is static, because there is only one and everyone shares it. Each student&#8217;s roll number is instance data, because every student has a different one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Static vs Instance Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The static vs instance choice changes how your data behaves. If you pick the wrong one, values may leak between objects or vanish when you expect them to stay.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Shared counters.<\/strong> A static variable can count how many batches your code created in a transaction.<\/li>\n\n<li><strong>Per-object data.<\/strong> Instance variables keep each batch&#8217;s seat count separate.<\/li>\n\n<li><strong>Utility methods.<\/strong> Static methods suit helpers that need no stored data, such as fee maths.<\/li>\n\n<li><strong>Trigger safety.<\/strong> Static flags stop a trigger from running twice in one transaction.<\/li>\n\n<li><strong>Clarity.<\/strong> Static methods show at a glance that they use no object state.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Static vs Instance Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When Apex loads a class in a transaction, it creates one set of static variables for that class. Every object created from the class then shares those static variables. Each object also gets its own fresh set of instance variables.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-1-1024x640.png\" alt=\"Static vs Instance diagram showing a shared static variable and per-object instance data\" class=\"wp-image-1242\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-1-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-1-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Static members are shared, while each object keeps its own instance data.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Static variables in Apex last only for one transaction. They are not shared between users or between separate requests. When the transaction ends, they disappear. Then a new transaction starts with fresh values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is different from Java, where static data can live as long as the server runs. In Salesforce, static means &#8220;shared for this one transaction&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Rules of Static vs Instance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex enforces a few clear static vs instance rules. Knowing them helps you read compile errors quickly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Static Methods Cannot Use Instance Members<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A static method has no object behind it. So it cannot read instance variables or call instance methods directly. It also cannot use the <code>this<\/code> keyword.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Instance Methods Can Use Static Members<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An instance method can read and change static variables, and it can call static methods. This is how every object can update a shared counter.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Constants Are Usually Static<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A constant like <code>MIN_FEE<\/code> is the same for every object. So it makes sense to write <code>static final<\/code>, which keeps one shared copy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Static Initialisation Blocks<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>static { }<\/code> block runs once, the first time Apex uses the class in a transaction. You can use it to load settings into static variables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Static vs Instance Side by Side<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares the two kinds of members on the points that matter most.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Static<\/th><th>Instance<\/th><\/tr><\/thead><tbody><tr><td>Belongs to<\/td><td>The class<\/td><td>Each object<\/td><\/tr><tr><td>Copies in memory<\/td><td>One per transaction<\/td><td>One per object<\/td><\/tr><tr><td>How to call<\/td><td>ClassName.member<\/td><td>objectName.member<\/td><\/tr><tr><td>Needs new first<\/td><td>No<\/td><td>Yes<\/td><\/tr><tr><td>Can use this<\/td><td>No<\/td><td>Yes<\/td><\/tr><tr><td>Lifetime<\/td><td>Until the transaction ends<\/td><td>Until the object is no longer used<\/td><\/tr><tr><td>Typical use<\/td><td>Helpers, constants, counters, flags<\/td><td>Data that differs per object<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is a simple question. Ask whether the value or action depends on one specific object. If yes, make it instance. If no, make it static.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-2-1024x640.png\" alt=\"Static vs Instance diagram comparing static and instance members\" class=\"wp-image-1243\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-2-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-2-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Static vs instance members side by side.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Static vs Instance Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s extend <code>CourseBatch<\/code> from the earlier post. Each batch keeps its own seat count, which is instance data. We also want a shared count of how many batches the code created in this transaction, which is static data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class CourseBatch {\n\n    \/\/ Static: one shared copy for the whole transaction\n    public static Integer batchesCreated = 0;\n\n    \/\/ Instance: every batch has its own values\n    public String courseName;\n    public Integer seatsBooked = 0;\n\n    public CourseBatch(String courseName) {\n        this.courseName = courseName;\n        batchesCreated++;          \/\/ instance code can update static data\n    }\n\n    public void enrol() {\n        seatsBooked++;\n    }\n\n    public static String summary() {\n        return 'Batches created: ' + batchesCreated;\n        \/\/ seatsBooked is not allowed here, because it is instance data\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The static variable <code>batchesCreated<\/code> starts at 0 once for the class. Every time the constructor runs, it adds 1 to that shared count. Meanwhile, <code>seatsBooked<\/code> belongs to each object, so each batch tracks its own students. The static <code>summary<\/code> method can read the static count but not any batch&#8217;s seats.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s use it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CourseBatch a = new CourseBatch('Apex Basics');\nCourseBatch b = new CourseBatch('LWC Basics');\n\na.enrol();\na.enrol();\nb.enrol();\n\nSystem.debug(a.courseName + ' seats: ' + a.seatsBooked);\nSystem.debug(b.courseName + ' seats: ' + b.seatsBooked);\nSystem.debug(CourseBatch.summary());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We call <code>enrol<\/code> on each object, and each keeps its own count. Then we call <code>summary<\/code> on the class itself, not on an object. The log shows this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>USER_DEBUG [8]|DEBUG|Apex Basics seats: 2\nUSER_DEBUG [9]|DEBUG|LWC Basics seats: 1\nUSER_DEBUG [10]|DEBUG|Batches created: 2<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Static Variables in Triggers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The most common real use of static variables is in triggers. Sometimes a trigger updates a record, which fires the same trigger again. Without a guard, the logic can run twice or loop. A static Set of processed Ids stops that.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class CourseTriggerGuard {\n    public static Set&lt;Id&gt; processedIds = new Set&lt;Id&gt;();\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Inside the trigger handler, you skip any record whose Id is already in <code>processedIds<\/code>. Then you add each new Id after you process it. Because the Set is static, it survives across the repeat trigger calls in the same transaction. When the transaction ends, it resets automatically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Many older examples use a single static Boolean flag instead. However, a flag can block valid records in large data loads, because Salesforce splits them into chunks of 200. The Set of Ids is the safer pattern.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Choosing Static vs Instance for Methods<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For methods, a quick test helps. Does the method read or change any instance variable? If not, it can probably be static.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pure helpers, such as <code>FeeCalculator.addTax<\/code>, are great as static methods. Anyone can call them without setting up an object. On the other hand, methods like <code>enrol<\/code> change one batch&#8217;s data, so they must be instance methods.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lightning Web Components add one more rule. Any Apex method a component calls with <code>@AuraEnabled<\/code> must be static. So you will write many static methods for components, even if they create objects inside.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Static vs Instance Quick Guide<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a quick guide for common members you will write. The table shows the usual static vs instance choice for each one.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Member<\/th><th>Usual choice<\/th><th>Reason<\/th><\/tr><\/thead><tbody><tr><td>Tax rate or minimum fee<\/td><td>Static final<\/td><td>Same for everyone<\/td><\/tr><tr><td>Fee calculation helper<\/td><td>Static method<\/td><td>Needs no stored data<\/td><\/tr><tr><td>A batch&#8217;s seat count<\/td><td>Instance variable<\/td><td>Differs per batch<\/td><\/tr><tr><td>enrol() on a batch<\/td><td>Instance method<\/td><td>Changes one batch<\/td><\/tr><tr><td>Trigger recursion Set<\/td><td>Static variable<\/td><td>Shared across trigger calls<\/td><\/tr><tr><td>Method called by LWC<\/td><td>Static method<\/td><td>Required by @AuraEnabled<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Use this guide as a starting point, not a strict law. If you are unsure, start with instance members for data and static members for pure helpers. Then adjust as the design becomes clear.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Static vs Instance in Interviews<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers love this topic because it shows whether you understand how Apex runs. Expect questions like &#8220;Can a static method call an instance method?&#8221; The answer is no, not directly. It must first create an object, or receive one as a parameter.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another common question is &#8220;How long does a static variable live in Apex?&#8221; The correct answer is one transaction. Many candidates say &#8220;forever&#8221; because they think of Java. In Salesforce, every new request starts with fresh static values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You may also get &#8220;How do you stop a trigger from running twice?&#8221; Here, describe the static Set of Ids pattern from this post. Mention why it beats a single Boolean flag in large data loads. A clear static vs instance answer like this shows real project experience.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Static vs Instance<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Calling an instance method on the class name. Create an object with <code>new<\/code> first.<\/li>\n\n<li>Using an instance variable inside a static method. Pass the value in as a parameter instead.<\/li>\n\n<li>Expecting static data to last across transactions. It resets every time a new transaction starts.<\/li>\n\n<li>Storing per-record data in a static variable. All objects then overwrite the same value.<\/li>\n\n<li>Using one static Boolean as a recursion guard. Use a static Set of Ids so large loads still work.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Static vs Instance<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Make helper methods static when they need no object data.<\/li>\n\n<li>Keep data that differs per object as instance variables.<\/li>\n\n<li>Use <code>static final<\/code> for constants, so there is one clear copy.<\/li>\n\n<li>Use static Sets of Ids for trigger recursion control.<\/li>\n\n<li>Keep static variables private when possible, and expose them through methods.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add a static variable <code>totalSeatsBooked<\/code> to <code>CourseBatch<\/code> that counts seats across all batches. Update <code>enrol<\/code> so it adds to both counts. Then create three batches, enrol five students in total and print both numbers. Hint: instance methods can update static variables directly.<\/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\/apex_classes_static.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Static and Instance Methods, Variables and Initialization Code<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_classes.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Classes, Objects and Interfaces<\/a><\/li>\n\n<li><a href=\"https:\/\/trailhead.salesforce.com\/content\/learn\/modules\/apex_database\" target=\"_blank\" rel=\"noopener noreferrer\">Trailhead: Apex Basics and Database<\/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>Static members belong to the class, while instance members belong to each object.<\/li>\n\n<li>In the Static vs Instance choice, ask if the data depends on one object.<\/li>\n\n<li>Static variables in Apex last only for one transaction.<\/li>\n\n<li>Static methods cannot use instance variables or <code>this<\/code>.<\/li>\n\n<li>Use a static Set of Ids to stop triggers from running twice.<\/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\">Apex also comes with many ready-made methods for text, dates and numbers. Next, read <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-built-in-methods-string-date-math\/\">Apex built-in methods for String, Date and Math<\/a> to save time on everyday tasks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Static vs Instance is one of the first design choices you make for every variable and method in Apex. A static member belongs to&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1241,"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,15,7,97],"swapz_series":[],"class_list":["post-1244","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","category-salesforce-developer","tag-apex","tag-beginner","tag-salesforce","tag-salesforce-developer"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Static vs Instance Members in Apex Explained<\/title>\n<meta name=\"description\" content=\"Static vs Instance members in Apex made simple: how static data is shared, how instance data belongs to each object, and when to use each.\" \/>\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\/static-vs-instance-apex\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Static vs Instance Members in Apex Explained\" \/>\n<meta property=\"og:description\" content=\"Static vs Instance members in Apex made simple: how static data is shared, how instance data belongs to each object, and when to use each.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-04T03:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-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=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\"},\"headline\":\"Static vs Instance Members in Apex Explained\",\"datePublished\":\"2026-09-04T03:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/\"},\"wordCount\":1576,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/static-vs-instance-apex-featured.png\",\"keywords\":[\"Apex\",\"Beginner\",\"Salesforce\",\"Salesforce Developer\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/\",\"name\":\"Static vs Instance Members in Apex Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/static-vs-instance-apex-featured.png\",\"datePublished\":\"2026-09-04T03:30:00+00:00\",\"description\":\"Static vs Instance members in Apex made simple: how static data is shared, how instance data belongs to each object, and when to use each.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/static-vs-instance-apex-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/static-vs-instance-apex-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Static vs Instance featured image: title card with static and instance variables\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/static-vs-instance-apex\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Static vs Instance Members in Apex Explained\"}]},{\"@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":"Static vs Instance Members in Apex Explained","description":"Static vs Instance members in Apex made simple: how static data is shared, how instance data belongs to each object, and when to use each.","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\/static-vs-instance-apex\/","og_locale":"en_US","og_type":"article","og_title":"Static vs Instance Members in Apex Explained","og_description":"Static vs Instance members in Apex made simple: how static data is shared, how instance data belongs to each object, and when to use each.","og_url":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-04T03:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a"},"headline":"Static vs Instance Members in Apex Explained","datePublished":"2026-09-04T03:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/"},"wordCount":1576,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-featured.png","keywords":["Apex","Beginner","Salesforce","Salesforce Developer"],"articleSection":["Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/","url":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/","name":"Static vs Instance Members in Apex Explained","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-featured.png","datePublished":"2026-09-04T03:30:00+00:00","description":"Static vs Instance members in Apex made simple: how static data is shared, how instance data belongs to each object, and when to use each.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/static-vs-instance-apex-featured.png","width":2400,"height":1260,"caption":"Static vs Instance featured image: title card with static and instance variables"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/static-vs-instance-apex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Static vs Instance Members in Apex Explained"}]},{"@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\/1244","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=1244"}],"version-history":[{"count":0,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1244\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1241"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1244"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}