{"id":2364,"date":"2026-10-16T09:00:00","date_gmt":"2026-10-16T03:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/"},"modified":"2026-11-15T11:30:24","modified_gmt":"2026-11-15T06:00:24","slug":"apex-wrapper-inner-classes","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/","title":{"rendered":"Apex Wrapper Classes and Inner Classes Explained with Examples"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">An Apex Wrapper Class is a small class you write to hold several values together as one object. The classic case is a table where each row needs a record plus a checkbox. SOQL cannot return that checkbox, so you wrap the record and add the field yourself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This post builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/\">Apex classes and objects<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-collections-list-set-map\/\">collections<\/a>. We will build a course selection screen for Bright Path Tutors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is an Apex Wrapper Class?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An Apex Wrapper Class is an ordinary class whose job is to carry data, not to run logic. It usually holds one sObject plus a few extra fields. Many developers write it as an inner class inside the controller that uses it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a school file. The student record is the form inside, and the folder adds a label, a tick box and a note on the cover. The folder is the wrapper.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why an Apex Wrapper Class Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Screens need more than the database holds. A table may need a Select checkbox, a running total, a status colour or a calculated label. None of those live on the object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So an Apex Wrapper Class gives the UI exactly the shape it needs, without adding useless fields to your objects. It also keeps your Apex readable, because each value has a proper name.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How an Apex Wrapper Class Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For an Apex Wrapper Class you query the records, loop over them, build one wrapper per record and return the list. The UI then reads both the record fields and your extra fields from the same row.<\/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-wrapper-inner-classes-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-diagram-1-1024x640.png\" alt=\"Apex Wrapper Class diagram showing how data flows from SOQL to the screen\" class=\"wp-image-2362\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">How records become wrappers and reach the screen.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Writing the Wrapper<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Fields must be public, or the UI layer cannot read them.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class CourseWrapper {\n    public Course__c course { get; set; }\n    public Boolean selected { get; set; }\n    public Decimal discountedFee { get; set; }\n\n    public CourseWrapper(Course__c c, Decimal fee) {\n        this.course = c;\n        this.selected = false;\n        this.discountedFee = fee;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>{ get; set; }<\/code> part creates a property, which Visualforce and LWC can both read.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Building the List<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class CourseController {\n    public static List&lt;CourseWrapper&gt; getRows() {\n        List&lt;CourseWrapper&gt; rows = new List&lt;CourseWrapper&gt;();\n        for (Course__c c : [SELECT Id, Name, Fee__c, Level__c\n                            FROM Course__c\n                            WHERE Is_Online__c = true\n                            ORDER BY Name\n                            LIMIT 200]) {\n            Decimal fee = c.Fee__c == null ? 0 : c.Fee__c * 0.9;\n            rows.add(new CourseWrapper(c, fee));\n        }\n        return rows;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">One query runs outside the loop, which keeps the code bulk safe. The discount is worked out per row.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Reading the Selected Rows Back<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public static List&lt;Id&gt; chosen(List&lt;CourseWrapper&gt; rows) {\n    List&lt;Id&gt; ids = new List&lt;Id&gt;();\n    for (CourseWrapper w : rows) {\n        if (w.selected == true) { ids.add(w.course.Id); }\n    }\n    return ids;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The debug output for two ticked rows looks like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(a01xx0000001AAA, a01xx0000001BBB)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Inner Classes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An inner class is a class defined inside another class. An Apex Wrapper Class is often written this way, because they belong to one controller.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class EnrolmentController {\n    \/\/ Inner class, used only here\n    public class Row {\n        @AuraEnabled public String studentName { get; set; }\n        @AuraEnabled public Decimal paid { get; set; }\n    }\n\n    @AuraEnabled(cacheable=true)\n    public static List&lt;Row&gt; load() {\n        List&lt;Row&gt; out = new List&lt;Row&gt;();\n        Row r = new Row();\n        r.studentName = 'Asha Mehta';\n        r.paid = 4500;\n        out.add(r);\n        return out;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For LWC, every field you want in JavaScript needs <code>@AuraEnabled<\/code>. Without it, the field simply does not arrive.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Inner Class Rules<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apex allows one level of nesting, so you cannot put an inner class inside an inner class. An inner class can be static or not, and outside code refers to it as <code>Outer.Inner<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Wrapper Class Field Checklist<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This table shows what to mark on wrapper fields for each use.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Where it is used<\/th><th>Field needs<\/th><th>Reason<\/th><\/tr><\/thead><tbody><tr><td>Visualforce page<\/td><td>public with get set<\/td><td>Page reads properties<\/td><\/tr><tr><td>Lightning Web Component<\/td><td>@AuraEnabled<\/td><td>Data crosses to JavaScript<\/td><\/tr><tr><td>Apex only<\/td><td>public or private<\/td><td>No UI layer involved<\/td><\/tr><tr><td>Sorting a list<\/td><td>Class implements Comparable<\/td><td>compareTo decides order<\/td><\/tr><tr><td>JSON output<\/td><td>public<\/td><td>Serializer reads public members<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapper Class vs Map<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Both can carry extra data. This table shows the difference.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Wrapper class<\/th><th>Map<\/th><\/tr><\/thead><tbody><tr><td>Named fields<\/td><td>Yes<\/td><td>No, only keys<\/td><\/tr><tr><td>Type safety<\/td><td>Strong<\/td><td>Weak, often Object<\/td><\/tr><tr><td>Readability<\/td><td>High<\/td><td>Lower<\/td><\/tr><tr><td>Best for<\/td><td>Table rows<\/td><td>Lookup by key<\/td><\/tr><tr><td>Sorting<\/td><td>Comparable support<\/td><td>Manual<\/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-wrapper-inner-classes-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-diagram-2-1024x640.png\" alt=\"Apex Wrapper Class compared with using a Map\" class=\"wp-image-2363\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Wrapper class compared with a Map for carrying extra data.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In short, use a wrapper when a row needs several named values. Use a Map when you only need to find something by a key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Apex Wrapper Class Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Bright Path wants a screen that lists courses with a checkbox and the fee after discount. Counsellors tick courses and click Enrol.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Define the Row<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class CourseSelector {\n    public class CourseRow {\n        @AuraEnabled public Id courseId { get; set; }\n        @AuraEnabled public String name { get; set; }\n        @AuraEnabled public Decimal fee { get; set; }\n        @AuraEnabled public Decimal payable { get; set; }\n        @AuraEnabled public Boolean selected { get; set; }\n    }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Fill the Rows<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>    @AuraEnabled(cacheable=true)\n    public static List&lt;CourseRow&gt; listCourses() {\n        List&lt;CourseRow&gt; rows = new List&lt;CourseRow&gt;();\n        for (Course__c c : [SELECT Id, Name, Fee__c FROM Course__c LIMIT 200]) {\n            CourseRow r = new CourseRow();\n            r.courseId = c.Id;\n            r.name = c.Name;\n            r.fee = c.Fee__c;\n            r.payable = (c.Fee__c == null) ? 0 : c.Fee__c - 500;\n            r.selected = false;\n            rows.add(r);\n        }\n        return rows;\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Check the Output<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Running <code>CourseSelector.listCourses()<\/code> in anonymous Apex and serialising it shows the shape JavaScript receives.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[{\"courseId\":\"a01...\",\"name\":\"Python Basics\",\"fee\":10000,\"payable\":9500,\"selected\":false}]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These are the fields and why each one exists.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Field<\/th><th>Source<\/th><th>Why<\/th><\/tr><\/thead><tbody><tr><td>courseId<\/td><td>Record<\/td><td>Needed to save later<\/td><\/tr><tr><td>name<\/td><td>Record<\/td><td>Shown in the table<\/td><\/tr><tr><td>fee<\/td><td>Record<\/td><td>Original price<\/td><\/tr><tr><td>payable<\/td><td>Calculated<\/td><td>Not stored on the object<\/td><\/tr><tr><td>selected<\/td><td>UI only<\/td><td>Tracks the checkbox<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with an Apex Wrapper Class<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Leaving fields private, so the UI shows blanks.<\/li>\n\n<li>Forgetting @AuraEnabled, so LWC receives nothing.<\/li>\n\n<li>Building wrappers inside a loop that also queries, which hits limits.<\/li>\n\n<li>Putting business logic in the wrapper instead of a service class.<\/li>\n\n<li>Returning hundreds of wrappers to a page that shows twenty rows.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for an Apex Wrapper Class<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep wrappers small and name every field clearly.<\/li>\n\n<li>Query once, then loop to build rows.<\/li>\n\n<li>Mark fields @AuraEnabled only when the UI truly needs them.<\/li>\n\n<li>Use an inner class when only one controller uses it.<\/li>\n\n<li>Implement Comparable when the list must be sorted.<\/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 a wrapper called StudentRow with studentName, totalPaid and isOverdue. Fill it from a SOQL query on Enrolment. Hint: mark every field @AuraEnabled if you plan to use it in LWC.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Apex Wrapper Class Interview Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Apex Wrapper Class questions are asked in almost every Salesforce developer interview.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Apex Wrapper Class Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What is a wrapper class in Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An Apex Wrapper Class is a custom class that holds several values as one object, usually an sObject plus extra fields.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: Why do you need a wrapper class?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because SOQL returns only stored fields, an Apex Wrapper Class fills the gap. A wrapper adds things like a checkbox or a calculated total.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: Give a common use case.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A table with a Select checkbox beside each record, so users tick rows and act on them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: What is an inner class?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is a class defined inside another class. An Apex Wrapper Class is often written this way.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: How deep can inner classes nest in Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One level only. You cannot define an inner class inside another inner class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: How do you refer to an inner class from outside?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the outer name first, like Outer.Inner.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: What must wrapper fields be for Visualforce?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Public, usually as properties with get and set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: What is needed for LWC?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each field must be marked @AuraEnabled, or it will not reach JavaScript.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Intermediate Apex Wrapper Class Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: Can a wrapper class hold a list?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. A wrapper can hold lists, maps, other wrappers and sObjects together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: How do you sort a list of wrappers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Make the wrapper implement Comparable and write compareTo, then call sort on the list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: Can a wrapper class be used in a Flow?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, if it is an @AuraEnabled inner class returned by an invocable method, or you expose fields as Apex-defined types.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: Does a wrapper class count against SOQL limits?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. The query counts, not the wrapper. However, building huge lists uses heap.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: Should a wrapper contain business logic?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep it light. A small helper method is fine, but real logic belongs in a service class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: What is the difference between an inner class and a separate class file?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An inner class lives inside one file and is usually used by that class only. A separate class is reusable across the org.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: Can an inner class be static?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. A static inner class does not need an instance of the outer class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: How does JSON.serialize treat a wrapper?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It writes public members as JSON keys, so the output matches your field names.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Apex Wrapper Class Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: Scenario: a page times out with 5,000 wrapper rows. What do you change?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Page the data with LIMIT and OFFSET or a key-set filter, and return only the fields the table shows.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: How do wrappers help heap limits?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They can hurt if you copy whole records. So keep only the fields you need rather than the full sObject.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: How would you build a wrapper for a parent with children?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hold the parent sObject and a List of child wrappers inside it, then build both in one or two queries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: Can a wrapper implement more than one interface?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. A common pair is Comparable for sorting plus a custom interface for your own contract.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: Scenario: LWC shows blank values but Apex debug looks fine. Why?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The fields are probably missing @AuraEnabled, so they are dropped in transit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22: How do you test a wrapper class?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Build instances in the test, call the methods that return them and assert on the field values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q23: When is a Map better than a wrapper?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you only need lookup by key, such as mapping record Id to a total.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q24: How do wrappers work with Apex-defined types in Flow?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Flow can consume an @AuraEnabled class as an Apex-defined variable, so screens read its fields directly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q25: Does an Apex Wrapper Class need a constructor?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. You can set fields one by one after calling new. However, a constructor keeps the building code short and readable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q26: Can an Apex Wrapper Class be reused across controllers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, if you make it a top-level class instead of an inner class. So choose top-level when two or more controllers need it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q27: How do you return an Apex Wrapper Class from a Visualforce controller?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Expose a public getter that returns the list, then loop it with apex:repeat or a pageBlockTable on the page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q28: What is the heap cost of wrappers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each wrapper holds references to its fields, so a full sObject copy is the expensive part. Therefore select only the columns you show.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q29: Scenario: the table must show a running total per row. Where do you calculate it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Work it out while building the wrapper list in Apex. So the UI just displays the number without extra logic.<\/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_defining.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Classes<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/lwc\/guide\/apex.html\" target=\"_blank\" rel=\"noopener noreferrer\">Lightning Web Components: Wire Apex Methods<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexref.meta\/apexref\/apex_interface_System_Comparable.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Comparable Interface<\/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>An Apex Wrapper Class packages a record plus extra fields.<\/li>\n\n<li>Fields must be public for Visualforce and @AuraEnabled for LWC.<\/li>\n\n<li>Inner classes nest one level and suit single-controller use.<\/li>\n\n<li>Query once, then build rows in a loop.<\/li>\n\n<li>Use Comparable when the list must be sorted.<\/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-enums-explained\/\">Enums in Apex<\/a>, a clean way to handle a fixed set of values.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An Apex Wrapper Class is a small class you write to hold several values together as one object. The classic case is a table&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2361,"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-2364","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 Wrapper Class and Inner Classes Explained<\/title>\n<meta name=\"description\" content=\"Learn the Apex Wrapper Class pattern and inner classes with real examples, use in Visualforce and LWC tables, plus the most asked 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-wrapper-inner-classes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex Wrapper Class and Inner Classes Explained\" \/>\n<meta property=\"og:description\" content=\"Learn the Apex Wrapper Class pattern and inner classes with real examples, use in Visualforce and LWC tables, plus the most asked interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-16T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-15T06:00:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-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=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"Apex Wrapper Classes and Inner Classes Explained with Examples\",\"datePublished\":\"2026-10-16T03:30:00+00:00\",\"dateModified\":\"2026-11-15T06:00:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/\"},\"wordCount\":1677,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-wrapper-inner-classes-featured.png\",\"keywords\":[\"Apex\",\"Certification\",\"Intermediate\"],\"articleSection\":[\"Apex Fundamentals\",\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/\",\"name\":\"Apex Wrapper Class and Inner Classes Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-wrapper-inner-classes-featured.png\",\"datePublished\":\"2026-10-16T03:30:00+00:00\",\"dateModified\":\"2026-11-15T06:00:24+00:00\",\"description\":\"Learn the Apex Wrapper Class pattern and inner classes with real examples, use in Visualforce and LWC tables, plus the most asked interview questions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-wrapper-inner-classes-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-wrapper-inner-classes-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex Wrapper Class featured image: code editor card with wrapper definition\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-wrapper-inner-classes\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex Wrapper Classes and Inner Classes Explained with 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 Wrapper Class and Inner Classes Explained","description":"Learn the Apex Wrapper Class pattern and inner classes with real examples, use in Visualforce and LWC tables, plus the most asked 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-wrapper-inner-classes\/","og_locale":"en_US","og_type":"article","og_title":"Apex Wrapper Class and Inner Classes Explained","og_description":"Learn the Apex Wrapper Class pattern and inner classes with real examples, use in Visualforce and LWC tables, plus the most asked interview questions.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-10-16T03:30:00+00:00","article_modified_time":"2026-11-15T06:00:24+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"Apex Wrapper Classes and Inner Classes Explained with Examples","datePublished":"2026-10-16T03:30:00+00:00","dateModified":"2026-11-15T06:00:24+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/"},"wordCount":1677,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-featured.png","keywords":["Apex","Certification","Intermediate"],"articleSection":["Apex Fundamentals","Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/","name":"Apex Wrapper Class and Inner Classes Explained","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-featured.png","datePublished":"2026-10-16T03:30:00+00:00","dateModified":"2026-11-15T06:00:24+00:00","description":"Learn the Apex Wrapper Class pattern and inner classes with real examples, use in Visualforce and LWC tables, plus the most asked interview questions.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-wrapper-inner-classes-featured.png","width":2400,"height":1260,"caption":"Apex Wrapper Class featured image: code editor card with wrapper definition"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-wrapper-inner-classes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apex Wrapper Classes and Inner Classes Explained with 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\/2364","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=2364"}],"version-history":[{"count":1,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2364\/revisions"}],"predecessor-version":[{"id":3057,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2364\/revisions\/3057"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/2361"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=2364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=2364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=2364"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=2364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}