{"id":2368,"date":"2026-10-16T13:00:00","date_gmt":"2026-10-16T07:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/"},"modified":"2026-11-15T11:30:22","modified_gmt":"2026-11-15T06:00:22","slug":"apex-enums-explained","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/","title":{"rendered":"Enums in Apex Explained with Real Examples"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apex Enums let you define a small fixed set of named values, such as PAID, DUE and OVERDUE. The compiler then refuses anything outside that list. So a typo like &#8220;Ovrdue&#8221; fails when you save the class, not three months later in production.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This post builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/\">Apex data types<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-conditional-statements-if-switch\/\">switch statements<\/a>. We will use fee status at Bright Path Tutors as the running example.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Apex Enums?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Enums are types whose value can only be one of the names you listed. Apex creates it with the <code>enum<\/code> keyword, and each name is a constant of that type. Enums are not strings and not numbers, although you can convert them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a traffic light. It can be red, amber or green, and nothing else. You cannot set it to purple, because those three are the only legal states.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Apex Enums Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Many orgs pass status around as plain text. One developer writes &#8220;Overdue&#8221;, another writes &#8220;OVERDUE&#8221;, and a comparison quietly fails.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Enums remove that whole class of bug. The list of valid values lives in one place, and the compiler enforces it everywhere. Also, when you add a value later, every switch statement shows up for review.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Apex Enums Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You declare Apex Enums once, then use them as a parameter type, a return type or a variable. Apex gives every enum two helpful methods automatically.<\/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-enums-explained-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-diagram-1-1024x640.png\" alt=\"Apex Enums diagram showing how an enum protects code from bad values\" class=\"wp-image-2366\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">How an enum keeps bad values out of your code.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Declaring an Enum<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An enum can be its own file or sit inside a class.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public enum FeeStatus { PAID, DUE, OVERDUE, WAIVED }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By convention the names are upper case, like constants.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using an Enum as a Type<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public class FeeService {\n    public static String describe(FeeStatus status) {\n        if (status == FeeStatus.OVERDUE) {\n            return 'Please pay immediately.';\n        }\n        return 'No action needed.';\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Calling <code>FeeService.describe(FeeStatus.OVERDUE)<\/code> works. Passing a string will not compile, which is the point.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Built-in Methods<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Every Apex enum gets <code>values()<\/code>, <code>name()<\/code> and <code>ordinal()<\/code> without you writing them.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (FeeStatus s : FeeStatus.values()) {\n    System.debug(s.name() + ' is at position ' + s.ordinal());\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The log shows each value with its zero-based position.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PAID is at position 0\nDUE is at position 1\nOVERDUE is at position 2\nWAIVED is at position 3<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Enums in a Switch Statement<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A switch on an enum is clean, because you do not quote anything.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static Decimal lateFee(FeeStatus status, Decimal amount) {\n    switch on status {\n        when OVERDUE { return amount * 0.05; }\n        when DUE     { return 0; }\n        when else    { return 0; }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You do not write <code>FeeStatus.OVERDUE<\/code> inside the when, because the type is already known.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Converting To and From Text<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Records store picklists as text, so you often convert at the edges.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Enum to text\nString asText = FeeStatus.OVERDUE.name();   \/\/ 'OVERDUE'\n\n\/\/ Text to enum, safely\nFeeStatus parsed = null;\nfor (FeeStatus s : FeeStatus.values()) {\n    if (s.name() == 'OVERDUE') { parsed = s; }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Apex has no built-in valueOf for custom enums, so a small loop or a Map is the usual approach.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Enums Method Summary<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This table lists what each built-in method returns.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Returns<\/th><th>Example result<\/th><\/tr><\/thead><tbody><tr><td>values()<\/td><td>A list of every value<\/td><td>(PAID, DUE, OVERDUE, WAIVED)<\/td><\/tr><tr><td>name()<\/td><td>The value as a String<\/td><td>&#8216;OVERDUE&#8217;<\/td><\/tr><tr><td>ordinal()<\/td><td>Zero-based position<\/td><td>2<\/td><\/tr><tr><td>equals()<\/td><td>Boolean comparison<\/td><td>true<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Enum vs String Constant<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Many teams use <code>public static final String<\/code> instead. This table compares them.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Enum<\/th><th>String constant<\/th><\/tr><\/thead><tbody><tr><td>Invalid value<\/td><td>Blocked at compile time<\/td><td>Allowed<\/td><\/tr><tr><td>List of all values<\/td><td>values()<\/td><td>Written by hand<\/td><\/tr><tr><td>Switch safety<\/td><td>Strong<\/td><td>None<\/td><\/tr><tr><td>Works with picklist text<\/td><td>Needs conversion<\/td><td>Direct<\/td><\/tr><tr><td>Readability<\/td><td>High<\/td><td>Medium<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-diagram-2-1024x640.png\" alt=\"Apex Enums compared with string constants in Salesforce\" class=\"wp-image-2367\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Enum compared with a string constant in Apex.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In short, use an enum for a small fixed set of internal states. Use text when the values come from outside, such as an API.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Apex Enums Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Bright Path charges a late fee that depends on how overdue a payment is. The bands are fixed, so an enum fits well.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Define the Bands<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public enum LateBand { NONE, WEEK_ONE, MONTH_ONE, SERIOUS }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Work Out the Band<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public class LateFeeCalculator {\n    public static LateBand band(Integer daysLate) {\n        if (daysLate &lt;= 0)  { return LateBand.NONE; }\n        if (daysLate &lt;= 7)  { return LateBand.WEEK_ONE; }\n        if (daysLate &lt;= 30) { return LateBand.MONTH_ONE; }\n        return LateBand.SERIOUS;\n    }\n\n    public static Decimal charge(Decimal fee, Integer daysLate) {\n        switch on band(daysLate) {\n            when NONE      { return 0; }\n            when WEEK_ONE  { return fee * 0.02; }\n            when MONTH_ONE { return fee * 0.05; }\n            when else      { return fee * 0.10; }\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Run It<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>System.debug(LateFeeCalculator.charge(10000, 0));\nSystem.debug(LateFeeCalculator.charge(10000, 5));\nSystem.debug(LateFeeCalculator.charge(10000, 20));\nSystem.debug(LateFeeCalculator.charge(10000, 90));<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The log shows one charge per band.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0\n200\n500\n1000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These are the bands and what each one costs.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Band<\/th><th>Days late<\/th><th>Charge<\/th><\/tr><\/thead><tbody><tr><td>NONE<\/td><td>0 or less<\/td><td>0<\/td><\/tr><tr><td>WEEK_ONE<\/td><td>1 to 7<\/td><td>2% of fee<\/td><\/tr><tr><td>MONTH_ONE<\/td><td>8 to 30<\/td><td>5% of fee<\/td><\/tr><tr><td>SERIOUS<\/td><td>Over 30<\/td><td>10% of fee<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Apex Enums<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Comparing an enum with a string, which never matches.<\/li>\n\n<li>Expecting a valueOf method, which Apex does not provide for custom enums.<\/li>\n\n<li>Storing ordinal() in a record, since positions shift when you reorder values.<\/li>\n\n<li>Using an enum for values that change often, such as product names.<\/li>\n\n<li>Forgetting a when else branch, which can leave a switch with no return.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Apex Enums<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep the list short, usually under ten values.<\/li>\n\n<li>Use upper case names, so they read as constants.<\/li>\n\n<li>Store name() in records, never ordinal().<\/li>\n\n<li>Add a when else branch to every switch.<\/li>\n\n<li>Build a Map from text to enum once if you convert often.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create an enum called ClassMode with ONLINE, OFFLINE and HYBRID. Write a method that returns a sentence for each, using a switch. Hint: include a when else branch.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Apex Enums Interview Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Apex Enums questions come up when interviewers test clean coding habits.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Apex Enums Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What is an enum in Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Enums are types with a fixed set of named values. A variable of that type can only hold one of those names.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: How do you declare one?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You declare Apex Enums with the enum keyword, for example public enum FeeStatus { PAID, DUE, OVERDUE }.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: What does values() return?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It returns a list of every value in the enum, in the order you declared them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: What does name() return?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It returns the value as a String, such as &#8216;OVERDUE&#8217;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: What does ordinal() return?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It returns the zero-based position of the value in the declaration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: Can an enum be used in a switch statement?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, and it is the cleanest use. You write the value names without quotes in each when.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: Can an enum have methods?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Apex enums are simple value lists, unlike enums in some other languages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: Where can you declare an enum?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In its own file or inside a class. Both are valid.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Intermediate Apex Enums Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: How do you convert a String into an enum?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Loop over values() and compare name(), or build a Map from String to the enum once and reuse it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: Why should you store name() and not ordinal()?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because reordering the declaration changes every ordinal, which silently corrupts stored data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: Can an enum be null?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. An enum variable can hold null, so check for it before using it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: Can you use an enum as a Map key?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Map of FeeStatus to Decimal is a common and readable pattern.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: Are enums allowed as method parameters and return types?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, both. That is the main way they add safety.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: Can an enum be used in a Flow or an invocable method?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not directly. Expose a String instead and convert inside your Apex.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: Do enums work with picklist fields?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not automatically. Picklists store text, so you convert between the two.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: Can two enums have the same value name?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, because each name is scoped to its own enum type.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Apex Enums Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: Scenario: a new status is added. What breaks and how do you find it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Any switch without a when else may now miss a case. So search for switch statements on that enum and review each one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: How would you map an enum to behaviour without a long switch?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Build a Map from the enum to an interface implementation, then call the matching class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: Why avoid enums for values that come from an external API?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because the API can send a value you never declared, and the conversion then fails. Text with validation is safer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: How do enums help code review?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The valid set is visible in one place, so reviewers can see every legal state at a glance.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: Can you serialise an enum to JSON?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, JSON.serialize writes the name. On the way back, deserialize into a String and convert.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22: Scenario: you must store the state on a record. What do you save?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save name() in a picklist or text field, then convert back when you read it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q23: Do enums affect governor limits?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. They are compile-time constructs and cost nothing at runtime.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q24: When is a Set of Strings better than an enum?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When the list is long, changes often, or is loaded from Custom Metadata rather than fixed in code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q25: Are Apex Enums faster than strings?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The difference is tiny, so speed is not the reason to choose them. Instead, pick them for safety and readability.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q26: Can you loop over Apex Enums?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. The values() method returns a list, so a for loop over it works normally.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q27: How do you unit test code that uses Apex Enums?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call the method once per value, often by looping values(). Then every branch of the switch is covered.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q28: Scenario: a picklist has twenty values that marketing changes monthly. Enum or not?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not an enum. Because the list changes often, read the picklist values at runtime instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q29: Can Apex Enums be used in a Set?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. A Set of FeeStatus works like any other set and is handy for allowed-state checks.<\/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\/langCon_apex_enums.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Enums<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/langCon_apex_switch.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Switch Statement<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/langCon_apex_primitives.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Data Types<\/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 Enums define a fixed set of named values.<\/li>\n\n<li>The compiler blocks anything outside that list.<\/li>\n\n<li>values(), name() and ordinal() come for free.<\/li>\n\n<li>Store name() in records, never ordinal().<\/li>\n\n<li>Use text instead when values come from outside systems.<\/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\">Next, we look at <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/\">Schema Describe and Dynamic Apex<\/a>, which reads your org&#8217;s metadata at runtime.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apex Enums let you define a small fixed set of named values, such as PAID, DUE and OVERDUE. The compiler then refuses anything outside&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2365,"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":[239,8,96],"tags":[98,34,26],"swapz_series":[],"class_list":["post-2368","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apex-fundamentals","category-salesforce","category-salesforce-developer","tag-apex","tag-certification","tag-intermediate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apex Enums Explained with Real Code Examples<\/title>\n<meta name=\"description\" content=\"Learn Apex Enums with real examples, values and name methods, enums in switch statements, and the most asked Salesforce developer interview questions.\" \/>\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-enums-explained\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex Enums Explained with Real Code Examples\" \/>\n<meta property=\"og:description\" content=\"Learn Apex Enums with real examples, values and name methods, enums in switch statements, and the most asked Salesforce developer interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-16T07:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-15T06:00:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-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\\\/apex-enums-explained\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-enums-explained\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"Enums in Apex Explained with Real Examples\",\"datePublished\":\"2026-10-16T07:30:00+00:00\",\"dateModified\":\"2026-11-15T06:00:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-enums-explained\\\/\"},\"wordCount\":1519,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-enums-explained\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-enums-explained-featured.png\",\"keywords\":[\"Apex\",\"Certification\",\"Intermediate\"],\"articleSection\":[\"Apex Fundamentals\",\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-enums-explained\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-enums-explained\\\/\",\"name\":\"Apex Enums Explained with Real Code Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-enums-explained\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-enums-explained\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-enums-explained-featured.png\",\"datePublished\":\"2026-10-16T07:30:00+00:00\",\"dateModified\":\"2026-11-15T06:00:22+00:00\",\"description\":\"Learn Apex Enums with real examples, values and name methods, enums in switch statements, and the most asked Salesforce developer interview questions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-enums-explained\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-enums-explained\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-enums-explained\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-enums-explained-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-enums-explained-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex Enums featured image: code editor card with enum definition\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-enums-explained\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Enums in Apex Explained with Real Examples\"}]},{\"@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 Enums Explained with Real Code Examples","description":"Learn Apex Enums with real examples, values and name methods, enums in switch statements, and the most asked Salesforce developer interview questions.","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-enums-explained\/","og_locale":"en_US","og_type":"article","og_title":"Apex Enums Explained with Real Code Examples","og_description":"Learn Apex Enums with real examples, values and name methods, enums in switch statements, and the most asked Salesforce developer interview questions.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-10-16T07:30:00+00:00","article_modified_time":"2026-11-15T06:00:22+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-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\/apex-enums-explained\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"Enums in Apex Explained with Real Examples","datePublished":"2026-10-16T07:30:00+00:00","dateModified":"2026-11-15T06:00:22+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/"},"wordCount":1519,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-featured.png","keywords":["Apex","Certification","Intermediate"],"articleSection":["Apex Fundamentals","Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/","name":"Apex Enums Explained with Real Code Examples","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-featured.png","datePublished":"2026-10-16T07:30:00+00:00","dateModified":"2026-11-15T06:00:22+00:00","description":"Learn Apex Enums with real examples, values and name methods, enums in switch statements, and the most asked Salesforce developer interview questions.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-enums-explained-featured.png","width":2400,"height":1260,"caption":"Apex Enums featured image: code editor card with enum definition"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-enums-explained\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Enums in Apex Explained with Real Examples"}]},{"@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\/2368","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=2368"}],"version-history":[{"count":1,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2368\/revisions"}],"predecessor-version":[{"id":3056,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2368\/revisions\/3056"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/2365"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=2368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=2368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=2368"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=2368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}