{"id":1236,"date":"2026-09-03T17:00:00","date_gmt":"2026-09-03T11:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/"},"modified":"2026-09-03T17:00:00","modified_gmt":"2026-09-03T11:30:00","slug":"apex-classes-and-objects-constructors","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/","title":{"rendered":"Apex Classes and Objects: Constructors Explained Simply"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apex Classes and Objects are the core of object-oriented programming in Salesforce. A class is a blueprint that describes some data and the actions you can perform on it. An object is a real thing built from that blueprint. Once you understand this pair, the rest of Apex starts to make sense.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So far, you have written classes full of static methods, such as <code>FeeCalculator<\/code> in the post on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-methods-parameters-return-types\/\">Apex methods<\/a>. Those classes acted like toolboxes. Now you will build classes that create objects with their own data. This builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/\">Apex data types<\/a> and the ideas from <a href=\"https:\/\/swapnilzambare.com\/blog\/what-is-salesforce-apex-first-class\/\">your first Apex class<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Apex Classes and Objects?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A class defines what something looks like and what it can do. It lists member variables, which hold data, and methods, which perform actions. An object, also called an instance, is one copy of that class with its own values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a cookie cutter and cookies. The cutter is the class. It decides the shape. Each cookie you press out is an object. All cookies share the same shape, but you can decorate each one differently. In the same way, every object from a class has the same fields, but each one holds its own values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Apex Classes and Objects Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Static methods are fine for simple calculations. However, real programs often need to track many things that each have their own state. Apex Classes and Objects handle this well. That is where objects shine.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Group related data.<\/strong> A course offer has a name, fee and seat count, all kept together.<\/li>\n\n<li><strong>Model real things.<\/strong> Each batch, invoice or cart becomes one object.<\/li>\n\n<li><strong>Wrapper classes.<\/strong> You can combine a record with extra values to send to a Lightning Web Component.<\/li>\n\n<li><strong>Cleaner code.<\/strong> Methods act on the object&#8217;s own data, so you pass fewer parameters.<\/li>\n\n<li><strong>Design patterns.<\/strong> Most professional Apex frameworks use Apex Classes and Objects at their core.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Apex Classes and Objects Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Classes and Objects follow a simple cycle. First, you write a class with member variables, a constructor and methods. Next, you create an object with the <code>new<\/code> keyword. Apex then runs the constructor to set up the object. Finally, you call methods on the object, and they work with that object&#8217;s data.<\/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-classes-and-objects-constructors-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-1-1024x640.png\" alt=\"Apex Classes and Objects diagram showing one class creating two separate objects\" class=\"wp-image-1234\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-1-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-1-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">One class can create many objects, each with its own values.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Each object lives in memory for the length of the transaction. If you create two objects from the same class, they are completely separate. Changing one does not change the other.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Parts of a Class<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A typical class has a few standard parts. The table below lists them with examples from Bright Path Tutors.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Part<\/th><th>Example<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td>Class declaration<\/td><td>public class CourseBatch<\/td><td>Names the blueprint<\/td><\/tr><tr><td>Member variables<\/td><td>String courseName; Integer seatsBooked;<\/td><td>Hold each object&#8217;s data<\/td><\/tr><tr><td>Constructor<\/td><td>public CourseBatch(String name, Integer max)<\/td><td>Sets up a new object<\/td><\/tr><tr><td>Methods<\/td><td>public Boolean enrol()<\/td><td>Actions on the object&#8217;s data<\/td><\/tr><tr><td>Properties<\/td><td>public Integer seatsLeft { get; }<\/td><td>Controlled access to data<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Member Variables<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You declare member variables inside the class but outside any method. Every object gets its own copy. If you do not give them a value, they start as null, just like any other variable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Constructors<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A constructor is a special method that runs when you create an object with <code>new<\/code>. It has the same name as the class and no return type. Its job is to set the starting values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you write no constructor, Apex gives you a default one with no parameters. As soon as you write your own, that default disappears, unless you add it back yourself.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The this Keyword<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Inside a class, <code>this<\/code> means &#8220;the current object&#8221;. It is handy when a parameter has the same name as a member variable. For example, <code>this.courseName = courseName;<\/code> copies the parameter into the object&#8217;s field.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Properties<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A property looks like a variable but can run code when you read or write it. The short form <code>{ get; set; }<\/code> creates a simple property. You can also make one read-only with <code>{ get; private set; }<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Apex Classes and Objects Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s model a course batch at Bright Path Tutors. Each batch has a course name, a maximum number of seats and a count of booked seats. Students can enrol until the batch is full.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class CourseBatch {\n\n    public String courseName { get; private set; }\n    public Integer maxSeats { get; private set; }\n    public Integer seatsBooked { get; private set; }\n\n    \/\/ Constructor sets the starting values\n    public CourseBatch(String courseName, Integer maxSeats) {\n        this.courseName = courseName;\n        this.maxSeats = maxSeats;\n        this.seatsBooked = 0;\n    }\n\n    public Boolean enrol() {\n        if (seatsBooked &gt;= maxSeats) {\n            return false;\n        }\n        seatsBooked++;\n        return true;\n    }\n\n    public Integer seatsLeft() {\n        return maxSeats - seatsBooked;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The three properties have public <code>get<\/code> and private <code>set<\/code>, so outside code can read them but not change them directly. The constructor uses <code>this<\/code> to copy the parameters into the object. Then <code>enrol<\/code> adds one seat unless the batch is full, and <code>seatsLeft<\/code> returns the free seats.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s create two objects and use them.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CourseBatch morning = new CourseBatch('Apex Basics', 2);\nCourseBatch evening = new CourseBatch('Apex Basics', 30);\n\nmorning.enrol();\nmorning.enrol();\nBoolean third = morning.enrol();\n\nevening.enrol();\n\nSystem.debug('Morning left: ' + morning.seatsLeft() + ', third enrol: ' + third);\nSystem.debug('Evening left: ' + evening.seatsLeft());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We create two separate batches from the same class. The morning batch fills up after two students, so the third <code>enrol<\/code> returns false. However, the evening batch has its own count and stays almost empty. So the log shows this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>USER_DEBUG [9]|DEBUG|Morning left: 0, third enrol: false\nUSER_DEBUG [10]|DEBUG|Evening left: 29<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Class vs Object<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Beginners often mix up the two words in Apex Classes and Objects. The table below makes the difference clear.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Class<\/th><th>Object<\/th><\/tr><\/thead><tbody><tr><td>What it is<\/td><td>A blueprint or template<\/td><td>One real instance of the blueprint<\/td><\/tr><tr><td>How many<\/td><td>Written once<\/td><td>Created as many times as needed<\/td><\/tr><tr><td>Created with<\/td><td>The class keyword in a file<\/td><td>The new keyword at run time<\/td><\/tr><tr><td>Holds data<\/td><td>Defines which data exists<\/td><td>Holds actual values<\/td><\/tr><tr><td>Example<\/td><td>CourseBatch<\/td><td>morning, evening<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is not really a choice, because you always need both. You write the class once, and then you create objects from it whenever your code needs one.<\/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-classes-and-objects-constructors-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-2-1024x640.png\" alt=\"Apex Classes and Objects diagram comparing a class and an object\" class=\"wp-image-1235\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-2-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-2-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Class vs object in Apex.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Overloading Constructors<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Like methods, you can overload constructors. This lets callers create objects in different ways. You can also call one constructor from another with <code>this(...)<\/code>, which avoids repeating code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Add to CourseBatch: a default of 30 seats\npublic CourseBatch(String courseName) {\n    this(courseName, 30);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now <code>new CourseBatch('LWC Basics')<\/code> creates a batch with 30 seats. The call <code>this(courseName, 30)<\/code> must be the first line in the constructor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapper Classes in Apex<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A wrapper class is a class that bundles a record with extra values. Developers use wrappers all the time to send data to Lightning Web Components. For example, a course card might need the course record and a flag that says whether it is nearly full.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class CourseCard {\n    @AuraEnabled public Course__c course;\n    @AuraEnabled public Boolean almostFull;\n\n    public CourseCard(Course__c course, Integer seatsLeft) {\n        this.course = course;\n        this.almostFull = seatsLeft &lt;= 3;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>@AuraEnabled<\/code> label lets a Lightning Web Component read these values. The constructor takes a record and a seat count, then works out the flag. You will use this pattern a lot when we reach LWC.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Classes and Objects vs sObjects<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce records in Apex are also objects, called sObjects. For example, <code>new Course__c(Name = 'Apex Basics')<\/code> creates an object from the Course__c type. The difference is that sObjects map to database records, and you can save them with DML. Your own classes live only in memory. We will cover sObjects in detail at the end of this level.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Inner Classes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can define a class inside another class. Developers call this an inner class. Apex allows one level of inner classes, which is enough for most needs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Inner classes are handy for small helper types that only make sense inside one outer class. For example, <code>CourseService<\/code> might hold an inner class <code>Result<\/code> with a success flag and a message. Wrapper classes are often written as inner classes for the same reason. The outer class keeps everything about one feature in a single file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Classes and Objects in Real Projects<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In real Salesforce projects, you will see Apex Classes and Objects everywhere. Service classes hold business logic, such as <code>EnrolmentService<\/code>. Selector classes hold queries, such as <code>CourseSelector<\/code>. Wrapper classes shape data for Lightning Web Components.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You will also meet objects created by Salesforce itself. For example, <code>HttpRequest<\/code> is a class you create with <code>new<\/code> when you call an outside system. Every time you write <code>new<\/code> followed by a type, you are creating an object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So the skills in this post are not just theory. They are the base for triggers, integrations and components in later levels. Practise Apex Classes and Objects now, and the advanced topics will feel much easier.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Apex Classes and Objects<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Forgetting <code>new<\/code>. Declaring <code>CourseBatch b;<\/code> only creates a null variable, not an object.<\/li>\n\n<li>Adding a return type to a constructor. Then Apex treats it as a normal method, and it never runs on <code>new<\/code>.<\/li>\n\n<li>Losing the default constructor. Once you write any constructor, add a no-argument one back if you still need it.<\/li>\n\n<li>Making every member variable public. Use private setters to protect the object&#8217;s data.<\/li>\n\n<li>Mixing up static and instance members. All objects share static data, which we cover two posts from now.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Apex Classes and Objects<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Name classes with nouns, such as <code>CourseBatch<\/code>, and methods with verbs, such as <code>enrol<\/code>.<\/li>\n\n<li>Set every member variable in the constructor, so no object starts half-ready.<\/li>\n\n<li>Use <code>{ get; private set; }<\/code> to let others read data without changing it.<\/li>\n\n<li>Keep classes focused on one idea. A class that does everything is hard to change.<\/li>\n\n<li>Use wrapper classes to shape data for components instead of adding fake fields to objects.<\/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 method <code>cancel()<\/code> to <code>CourseBatch<\/code> that frees one seat but never goes below zero. Create a batch, enrol three students, cancel one, and print the seats left. Hint: check <code>seatsBooked &gt; 0<\/code> before you subtract.<\/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.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Classes, Objects and Interfaces<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_classes_constructors.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Using Constructors<\/a><\/li>\n\n<li><a href=\"https:\/\/trailhead.salesforce.com\/content\/learn\/modules\/object-oriented-programming-for-admins\" target=\"_blank\" rel=\"noopener noreferrer\">Trailhead: Object-Oriented Programming for Admins<\/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>A class is a blueprint, and an object is one real instance of it.<\/li>\n\n<li>Apex Classes and Objects group data and actions together.<\/li>\n\n<li>A constructor shares the class name, has no return type, and runs on <code>new<\/code>.<\/li>\n\n<li><code>this<\/code> refers to the current object, and <code>this(...)<\/code> calls another constructor.<\/li>\n\n<li>Wrapper classes bundle records with extra values for components.<\/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\">You have used <code>public<\/code> and <code>private<\/code> many times now. Next, learn exactly what they mean in <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-access-modifiers\/\">Apex access modifiers<\/a>, including <code>protected<\/code> and <code>global<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apex Classes and Objects are the core of object-oriented programming in Salesforce. A class is a blueprint that describes some data and the actions&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1233,"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-1236","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 Classes and Objects: Constructors Explained<\/title>\n<meta name=\"description\" content=\"Apex Classes and Objects explained simply: blueprints, member variables, constructors, the this keyword, properties and wrapper classes.\" \/>\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-classes-and-objects-constructors\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex Classes and Objects: Constructors Explained\" \/>\n<meta property=\"og:description\" content=\"Apex Classes and Objects explained simply: blueprints, member variables, constructors, the this keyword, properties and wrapper classes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-03T11:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-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-classes-and-objects-constructors\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-classes-and-objects-constructors\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\"},\"headline\":\"Apex Classes and Objects: Constructors Explained Simply\",\"datePublished\":\"2026-09-03T11:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-classes-and-objects-constructors\\\/\"},\"wordCount\":1583,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-classes-and-objects-constructors\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-classes-and-objects-constructors-featured.png\",\"keywords\":[\"Apex\",\"Beginner\",\"Salesforce\",\"Salesforce Developer\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-classes-and-objects-constructors\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-classes-and-objects-constructors\\\/\",\"name\":\"Apex Classes and Objects: Constructors Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-classes-and-objects-constructors\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-classes-and-objects-constructors\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-classes-and-objects-constructors-featured.png\",\"datePublished\":\"2026-09-03T11:30:00+00:00\",\"description\":\"Apex Classes and Objects explained simply: blueprints, member variables, constructors, the this keyword, properties and wrapper classes.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-classes-and-objects-constructors\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-classes-and-objects-constructors\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-classes-and-objects-constructors\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-classes-and-objects-constructors-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-classes-and-objects-constructors-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex Classes and Objects featured image: title card with a class and a new object\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-classes-and-objects-constructors\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex Classes and Objects: Constructors Explained Simply\"}]},{\"@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 Classes and Objects: Constructors Explained","description":"Apex Classes and Objects explained simply: blueprints, member variables, constructors, the this keyword, properties and wrapper classes.","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-classes-and-objects-constructors\/","og_locale":"en_US","og_type":"article","og_title":"Apex Classes and Objects: Constructors Explained","og_description":"Apex Classes and Objects explained simply: blueprints, member variables, constructors, the this keyword, properties and wrapper classes.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-03T11:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-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-classes-and-objects-constructors\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a"},"headline":"Apex Classes and Objects: Constructors Explained Simply","datePublished":"2026-09-03T11:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/"},"wordCount":1583,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-featured.png","keywords":["Apex","Beginner","Salesforce","Salesforce Developer"],"articleSection":["Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/","name":"Apex Classes and Objects: Constructors Explained","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-featured.png","datePublished":"2026-09-03T11:30:00+00:00","description":"Apex Classes and Objects explained simply: blueprints, member variables, constructors, the this keyword, properties and wrapper classes.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-classes-and-objects-constructors-featured.png","width":2400,"height":1260,"caption":"Apex Classes and Objects featured image: title card with a class and a new object"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apex Classes and Objects: Constructors Explained Simply"}]},{"@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\/1236","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=1236"}],"version-history":[{"count":0,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1236\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1233"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1236"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}