{"id":1212,"date":"2026-09-02T17:00:00","date_gmt":"2026-09-02T11:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/"},"modified":"2026-09-02T17:00:00","modified_gmt":"2026-09-02T11:30:00","slug":"apex-data-types-variables-constants","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/","title":{"rendered":"Apex Data Types, Variables and Constants Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apex Data Types decide what kind of value each variable can hold. For example, a variable may hold a number, some text or a date. Every line of Apex you write uses them. If you pick the right type, your code stays correct and easy to read. If you pick the wrong one, you get rounding errors and confusing bugs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the last post, you wrote your first class in <a href=\"https:\/\/swapnilzambare.com\/blog\/what-is-salesforce-apex-first-class\/\">What is Salesforce Apex?<\/a>. Then you ran it in the <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-developer-console-guide\/\">Developer Console<\/a>. Now we look closely at variables, constants and the types behind them. We will keep using the Course__c object from our <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-data-model-explained-objects-fields-and-relationships-for-beginners\/\">data model post<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Apex Data Types?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A data type tells Apex what kind of value a variable stores and what you can do with it. For example, you can add two numbers, but you cannot add a number to a date in the same way. Apex checks these data types when it compiles your code. So many mistakes show up before the code ever runs, which saves you time in testing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of variables as labelled jars in a kitchen. One jar is only for sugar, another only for rice. The label is the data type. You cannot pour rice into the sugar jar, and Apex will not let you put text into a number variable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Apex Data Types Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Choosing the right Apex Data Types is not just a style choice. It affects how your code behaves in real situations.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Money stays exact.<\/strong> <code>Decimal<\/code> keeps fees like 4999.50 precise, while other number types can round.<\/li>\n\n<li><strong>Errors appear early.<\/strong> The compiler catches a text value going into a number field.<\/li>\n\n<li><strong>Fields match.<\/strong> Each Salesforce field type maps to an Apex type, so your code fits the data.<\/li>\n\n<li><strong>Code reads clearly.<\/strong> A teammate sees <code>Date startDate<\/code> and knows what it holds at once.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Variables Work in Apex<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A variable has three parts: a type, a name and an optional starting value. You write them in that order and end with a semicolon.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer seats = 30;\nString courseName = 'Apex Basics';\nDecimal fee = 4999.50;\nBoolean isOnline = true;\nDate startDate = Date.newInstance(2026, 9, 15);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each line creates one variable. For example, <code>seats<\/code> is an <code>Integer<\/code> that starts at 30. The <code>startDate<\/code> line uses <code>Date.newInstance<\/code> to build a date from a year, month and day.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-1-1024x640.png\" alt=\"Apex Data Types diagram showing Integer, Decimal, String, Boolean, Date and Id\" class=\"wp-image-1210\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-1-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-1-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The main Apex data types with a short example of each.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Variables Start as null<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you declare a variable without a value, it starts as <code>null<\/code>. This is true for every type in Apex, even <code>Boolean<\/code> and <code>Integer<\/code>. So <code>Integer count;<\/code> does not hold 0. It holds nothing at all.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This catches many beginners. If you try <code>count + 1<\/code> while <code>count<\/code> is null, Apex throws a NullPointerException. So always give number variables a starting value, such as <code>Integer count = 0;<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Naming Rules<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Variable names must start with a letter. They can contain letters, numbers and underscores, but no spaces. Most Salesforce teams use camelCase, such as <code>maxStudents<\/code> or <code>courseFee<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Main Apex Data Types<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex has a set of built-in types called primitives. These are the Apex Data Types you will use every day. The table below lists the ones you will use most often, with a Bright Path Tutors example for each.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Type<\/th><th>What it holds<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>Integer<\/td><td>Whole numbers up to about 2.1 billion<\/td><td>Integer seats = 30;<\/td><\/tr><tr><td>Long<\/td><td>Very large whole numbers<\/td><td>Long views = 9000000000L;<\/td><\/tr><tr><td>Decimal<\/td><td>Exact numbers with decimals<\/td><td>Decimal fee = 4999.50;<\/td><\/tr><tr><td>Double<\/td><td>Large numbers with decimals<\/td><td>Double ratio = 0.333;<\/td><\/tr><tr><td>String<\/td><td>Text in single quotes<\/td><td>String level = &#8216;Beginner&#8217;;<\/td><\/tr><tr><td>Boolean<\/td><td>true, false or null<\/td><td>Boolean isOnline = true;<\/td><\/tr><tr><td>Date<\/td><td>A calendar date<\/td><td>Date d = Date.today();<\/td><\/tr><tr><td>Datetime<\/td><td>A date with a time<\/td><td>Datetime now = Datetime.now();<\/td><\/tr><tr><td>Id<\/td><td>An 18-character record Id<\/td><td>Id courseId = c.Id;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Numbers: Integer, Long, Decimal and Double<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>Integer<\/code> for counts, such as seats or weeks. Use <code>Long<\/code> only when a number may pass about 2.1 billion. For money and percentages, use <code>Decimal<\/code>, because currency fields in Salesforce map to it. <code>Double<\/code> is fine for science-style values where tiny rounding does not matter.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Text: String<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>String<\/code> holds any text, from one letter to a long paragraph. Always use single quotes. To add a quote inside text, use a backslash, such as <code>'Asha\\'s course'<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">True or False: Boolean<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>Boolean<\/code> answers yes or no questions, such as &#8220;Is this course online?&#8221;. Checkbox fields in Salesforce map to <code>Boolean<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Dates and Times<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Date<\/code> holds a day with no time, such as a course start date. <code>Datetime<\/code> holds a day plus a time, such as when a student logged in. There is also <code>Time<\/code> for a time with no date.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Id<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>Id<\/code> type holds a Salesforce record Id. Apex checks that the value really looks like an Id, so it is safer than storing Ids in a <code>String<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Constants in Apex<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A constant is a variable whose value never changes after you set it. In Apex, you create one with the <code>final<\/code> keyword. Most constants also use <code>static<\/code>, so the class shares one copy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class CourseRules {\n    \/\/ Constants are written in capital letters by convention\n    public static final Integer MAX_SEATS = 40;\n    public static final Decimal MIN_FEE = 500;\n    public static final String DEFAULT_LEVEL = 'Beginner';\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now any code can use <code>CourseRules.MAX_SEATS<\/code>. If someone tries to change it later, such as <code>CourseRules.MAX_SEATS = 50;<\/code>, the compiler stops them. Constants remove &#8220;magic numbers&#8221; scattered across your code, so a rule lives in one clear place.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Variables vs Constants<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares variables and constants side by side.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Variable<\/th><th>Constant<\/th><\/tr><\/thead><tbody><tr><td>Keyword<\/td><td>None needed<\/td><td>final, often with static<\/td><\/tr><tr><td>Can change later<\/td><td>Yes<\/td><td>No<\/td><\/tr><tr><td>Naming style<\/td><td>camelCase, such as courseFee<\/td><td>CAPITALS, such as MIN_FEE<\/td><\/tr><tr><td>Typical use<\/td><td>Values that change while code runs<\/td><td>Fixed rules and limits<\/td><\/tr><tr><td>Example<\/td><td>Integer seatsLeft = 12;<\/td><td>static final Integer MAX_SEATS = 40;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is easy. Use a variable when the value changes, and a constant when it is a fixed rule.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-2-1024x640.png\" alt=\"Apex Data Types diagram comparing variables and constants\" class=\"wp-image-1211\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-2-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-2-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Variables vs constants in Apex.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Apex Data Types Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s put Apex Data Types to work for Bright Path Tutors. We want to check a course before we open it for sign-ups. The course needs a fee of at least 500, and the start date must be in the future.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Values for a new course\nString courseName = 'LWC Basics';\nDecimal fee = 3500.00;\nInteger seatsBooked = 12;\nDate startDate = Date.today().addDays(10);\nBoolean isOnline = true;\n\n\/\/ Work out the result\nInteger seatsLeft = CourseRules.MAX_SEATS - seatsBooked;\nBoolean feeOk = fee &gt;= CourseRules.MIN_FEE;\nBoolean dateOk = startDate &gt; Date.today();\n\nSystem.debug(courseName + ' | seats left: ' + seatsLeft);\nSystem.debug('Ready to open: ' + (feeOk &amp;&amp; dateOk));<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first block stores values in five different types. Then <code>seatsLeft<\/code> uses the <code>MAX_SEATS<\/code> constant to work out free seats. Next, two <code>Boolean<\/code> variables hold the results of simple checks. Finally, <code>System.debug<\/code> joins text and numbers into one message. Run it in anonymous Apex, and the log shows this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>USER_DEBUG [12]|DEBUG|LWC Basics | seats left: 28\nUSER_DEBUG [13]|DEBUG|Ready to open: true<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Converting Between Apex Data Types<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes data arrives in the wrong type. For example, a value from a web form often comes as text. Apex gives you <code>valueOf<\/code> methods to convert it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String seatsText = '25';\nInteger seats = Integer.valueOf(seatsText);\n\nString feeText = '4999.50';\nDecimal fee = Decimal.valueOf(feeText);\n\nString label = String.valueOf(seats) + ' seats';\nSystem.debug(label);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Integer.valueOf<\/code> turns text into a whole number, and <code>Decimal.valueOf<\/code> turns text into an exact decimal. <code>String.valueOf<\/code> goes the other way and turns any value into text. If the text is not a valid number, such as <code>'abc'<\/code>, Apex throws a TypeException, so check your input first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Salesforce Fields Map to Apex Data Types<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every field you create in Object Manager has a matching Apex type. When you read a record in Apex, the field value arrives in that type. So it helps to know the mapping by heart.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Text, Text Area, Email, Phone, URL and Picklist fields become <code>String<\/code>.<\/li>\n\n<li>Number fields with no decimals still arrive as <code>Decimal<\/code>.<\/li>\n\n<li>Currency and Percent fields become <code>Decimal<\/code>.<\/li>\n\n<li>Checkbox fields become <code>Boolean<\/code>.<\/li>\n\n<li>Date fields become <code>Date<\/code>, and Date\/Time fields become <code>Datetime<\/code>.<\/li>\n\n<li>Lookup and Master-Detail fields hold an <code>Id<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Look at the Number field point closely. Our Duration_in_Weeks__c field is a Number, so Apex gives you a <code>Decimal<\/code>. If you want an <code>Integer<\/code>, you convert it with <code>.intValue()<\/code>, such as <code>Integer weeks = c.Duration_in_Weeks__c.intValue();<\/code>. This small detail trips up many new developers, so keep this list of Apex Data Types close.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Data Types and null Safety<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Because every variable can be null, safe code checks for it. The classic way is an <code>if<\/code> check before you use the value. However, Apex also has two short operators that make this easier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The safe navigation operator <code>?.<\/code> returns null instead of throwing an error when the left side is null. For example, <code>c?.Fee__c<\/code> gives null if <code>c<\/code> is null. The null coalescing operator <code>??<\/code> gives a fallback value, such as <code>Decimal fee = c.Fee__c ?? 0;<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Together, these keep your code short and safe. We will use both again in the next post on operators. For now, remember the rule. Before you do maths with any of the Apex Data Types, make sure the value is not null.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Apex Data Types<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using <code>Double<\/code> for money. Use <code>Decimal<\/code>, so fees never pick up tiny rounding errors.<\/li>\n\n<li>Expecting new variables to be 0 or false. They start as null, so set a value first.<\/li>\n\n<li>Using double quotes for text. Apex only accepts single quotes.<\/li>\n\n<li>Storing Ids in a <code>String<\/code>. The <code>Id<\/code> type checks the format for you.<\/li>\n\n<li>Hardcoding the same number in many places. Put it in a constant instead.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Apex Data Types<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Match each variable to the field type it works with, such as <code>Decimal<\/code> for currency fields.<\/li>\n\n<li>Give every number variable a starting value, so you never add to null.<\/li>\n\n<li>Use clear camelCase names that describe the value, like <code>seatsLeft<\/code>.<\/li>\n\n<li>Keep business rules in <code>static final<\/code> constants inside one class.<\/li>\n\n<li>Convert text with <code>valueOf<\/code> inside a try-catch when the input comes from users.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Write anonymous Apex that stores a course fee of 7200 and a discount of 15. Also store a start date 30 days from today. Then print the final fee and the start date. Hint: use <code>Decimal<\/code> for both numbers and <code>Date.today().addDays(30)<\/code> for the date.<\/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_primitives.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Primitive Data Types<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_variables.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Variables<\/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>Apex Data Types decide what each variable can hold.<\/li>\n\n<li>New variables start as null, even numbers and Booleans.<\/li>\n\n<li>Use <code>Decimal<\/code> for money, <code>Integer<\/code> for counts and <code>Id<\/code> for record Ids.<\/li>\n\n<li>Constants use <code>final<\/code>, usually with <code>static<\/code>, and never change.<\/li>\n\n<li>Convert text to numbers with <code>Integer.valueOf<\/code> and <code>Decimal.valueOf<\/code>.<\/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\">Now that you can store values, you need to work with them. Next, read <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/\">Apex operators and expressions<\/a> to learn how to add, compare and combine values.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apex Data Types decide what kind of value each variable can hold. For example, a variable may hold a number, some text or a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1209,"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-1212","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>Apex Data Types, Variables and Constants Explained<\/title>\n<meta name=\"description\" content=\"Apex Data Types made simple: Integer, Decimal, String, Boolean, Date and Id, plus how to declare variables, constants and convert types.\" \/>\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-data-types-variables-constants\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex Data Types, Variables and Constants Explained\" \/>\n<meta property=\"og:description\" content=\"Apex Data Types made simple: Integer, Decimal, String, Boolean, Date and Id, plus how to declare variables, constants and convert types.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-02T11:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-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-data-types-variables-constants\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-data-types-variables-constants\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\"},\"headline\":\"Apex Data Types, Variables and Constants Explained\",\"datePublished\":\"2026-09-02T11:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-data-types-variables-constants\\\/\"},\"wordCount\":1573,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-data-types-variables-constants\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-data-types-variables-constants-featured.png\",\"keywords\":[\"Apex\",\"Beginner\",\"Salesforce\",\"Salesforce Developer\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-data-types-variables-constants\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-data-types-variables-constants\\\/\",\"name\":\"Apex Data Types, Variables and Constants Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-data-types-variables-constants\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-data-types-variables-constants\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-data-types-variables-constants-featured.png\",\"datePublished\":\"2026-09-02T11:30:00+00:00\",\"description\":\"Apex Data Types made simple: Integer, Decimal, String, Boolean, Date and Id, plus how to declare variables, constants and convert types.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-data-types-variables-constants\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-data-types-variables-constants\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-data-types-variables-constants\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-data-types-variables-constants-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-data-types-variables-constants-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex Data Types featured image: title card with variable declarations\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-data-types-variables-constants\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex Data Types, Variables and Constants 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":"Apex Data Types, Variables and Constants Explained","description":"Apex Data Types made simple: Integer, Decimal, String, Boolean, Date and Id, plus how to declare variables, constants and convert types.","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-data-types-variables-constants\/","og_locale":"en_US","og_type":"article","og_title":"Apex Data Types, Variables and Constants Explained","og_description":"Apex Data Types made simple: Integer, Decimal, String, Boolean, Date and Id, plus how to declare variables, constants and convert types.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-02T11:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-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-data-types-variables-constants\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a"},"headline":"Apex Data Types, Variables and Constants Explained","datePublished":"2026-09-02T11:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/"},"wordCount":1573,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-featured.png","keywords":["Apex","Beginner","Salesforce","Salesforce Developer"],"articleSection":["Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/","name":"Apex Data Types, Variables and Constants Explained","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-featured.png","datePublished":"2026-09-02T11:30:00+00:00","description":"Apex Data Types made simple: Integer, Decimal, String, Boolean, Date and Id, plus how to declare variables, constants and convert types.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-data-types-variables-constants-featured.png","width":2400,"height":1260,"caption":"Apex Data Types featured image: title card with variable declarations"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apex Data Types, Variables and Constants 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\/1212","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=1212"}],"version-history":[{"count":0,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1212\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1209"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1212"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}