Hi Karthik, A wrapper or container class is a class, data structure, or an abstract data type whose instances are a collections of other objects.It is a custom object defined by Salesforce developer where he defines the properties of the wrapper class. Within Apex & Visualforce this can be extremely helpful to achieve many business scenarios within the Salesforce CRM software. Using Wrapper classes we can have the ability to check few records from the displayed list and process them for some action.  Please find the below article for details of the wrapper class. https://www.forcetalks.com/blog/what-is-wrapper-class-in-salesforce-everything-you-need-to-know/ If this solution helps, Please mark it as best answer. Thanks, Answer from Sai Praveen Kumar Kakkirala on trailhead.salesforce.com
๐ŸŒ
Apex Hours
apexhours.com โ€บ home โ€บ salesforce developer โ€บ wrapper class in salesforce
Wrapper Class in Salesforce - Apex Hours
August 1, 2025 - A wrapper or container class is a class, data structure, or abstract data type whose instances are collections of other objects. It is a custom object defined by a Salesforce developer where he defines the properties of the wrapper class.
๐ŸŒ
Salesforce Ben
salesforceben.com โ€บ home โ€บ what is a wrapper class in salesforce?
What Is a Wrapper Class in Salesforce? | Salesforce Ben
October 19, 2023 - A Wrapper Class, in simple terms, is an object created in Apex โ€“ similar to a custom object but created in code. This data lives only in code during your transaction and does not consume database storage.
Discussions

Salesforce Integration: Wrapper Class vs. Maps for Web Service Bulk Insert โ€“ Which is Better?
Wrapper classes for web services are a good use of wrapper classes. Then you can handle any changes to the webservice in the future by just modifying the wrapper classes as opposed to the Case object itself For large datasets, if this is even necessary, youโ€™ll need to set up some kind of staging and queue to chunk up that dataset and feed it into salesforce. Sure the batch classes exist, but the best throughput will be via the bulk api which is externally called. So if your datasets are so large you need this, then forego the wrapper class and set up a middleware to do the wrapper logic for you, and transform that webservice call into case record rows the bulk api can process through into salesforce More on reddit.com
๐ŸŒ r/SalesforceDeveloper
14
13
December 13, 2024
lightning web components - LWC With Apex Wrapper class to Display current user and its Contact - Salesforce Stack Exchange
I'm writing an LWC using Apex Wrapper Class. I'm, stuck in editing the JS and HTML for this. Can y'all please help with the same? Basically, I want to display like this: The User is: [Current user ... More on salesforce.stackexchange.com
๐ŸŒ salesforce.stackexchange.com
February 11, 2023
How do we implement a custom put() method for a wrapper class in APEX? - Salesforce Stack Exchange
I'm looking to create a generic wrapper APEX class with few property fields (string type for now). Here is what my class would look like: public class wCustomWrapper { public String customProp1... More on salesforce.stackexchange.com
๐ŸŒ salesforce.stackexchange.com
salesforce - How to Access Nested Wrapper Class in Flow Apex Action? - Stack Overflow
I'm working on an Apex Invocable Method that returns a wrapper class with nested wrapper objects. However, in Flow, I'm unable to access the inner wrapper fields properly. Hereโ€™s a simplified versi... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Reddit
reddit.com โ€บ r/salesforcedeveloper โ€บ salesforce integration: wrapper class vs. maps for web service bulk insert โ€“ which is better?
r/SalesforceDeveloper on Reddit: Salesforce Integration: Wrapper Class vs. Maps for Web Service Bulk Insert โ€“ Which is Better?
December 13, 2024 -

Hi Salesforce community,

Iโ€™m working on an integration that involves handling bulk insertion of Case records through a web service in Salesforce. I'm debating between using Wrapper Classes and Maps in my Apex implementation and would appreciate your thoughts on the following:

  1. Performance: Which approach offers better CPU and memory optimization for handling high volumes of data (e.g., 10,000+ records)?

  2. Governor Limits: Are there significant differences in how these approaches impact Salesforce governor limits, such as heap size or CPU time?

  3. Complexity: Wrapper Classes seem to be more intuitive for handling validation and transformations, but is this extra effort justified for simpler integrations?

  4. Scalability: Which approach scales better for large datasets or integrations with frequent data loads?

  5. Use Cases: Are there specific scenarios where one clearly outperforms the other?

If anyone has tackled a similar integration or has insights from a performance or maintainability perspective, I'd love to hear your experiences or best practices.

Additionally, after completing the Case insert operation, I need to send a JSON response back to the web service containing the CaseNumber of all successfully inserted records. How can I efficiently achieve this in Apex, especially for large datasets?

Thanks in advance!

Top answer
1 of 11
8
Wrapper classes for web services are a good use of wrapper classes. Then you can handle any changes to the webservice in the future by just modifying the wrapper classes as opposed to the Case object itself For large datasets, if this is even necessary, youโ€™ll need to set up some kind of staging and queue to chunk up that dataset and feed it into salesforce. Sure the batch classes exist, but the best throughput will be via the bulk api which is externally called. So if your datasets are so large you need this, then forego the wrapper class and set up a middleware to do the wrapper logic for you, and transform that webservice call into case record rows the bulk api can process through into salesforce
2 of 11
5
CPU time difference between Maps and Wrapper class would be negligible, as the most resources heavy thing is deserialisation of a payload into the usable thing - should not matter whether we serialise into the map or the class, however I did not benchmark it by any means, maybe JSON.deserialiseUntyped is significantly faster but I doubt it. If you have existing JSON, you can use online tool to create a Wrapper class in second - https://json2apex.github.io/   The only reason why I would go for maps is if I know that the incoming payload will frequently change in the near future, but that's a big issue nevertheless - if new fields are coming, how are you going to handle them and map into the Case without touching code? There is dynamic Apex approach with sobject.put() method, but performance wise it's gonna be much slower and wore in error handling and maintenance. Wrappers are simple, readable, and enforce data types which is much better to handle in development. I'd go for wrapper.
๐ŸŒ
Get Generative
getgenerative.ai โ€บ wrapper-class-in-salesforce
Wrapper Class in Salesforce
August 24, 2025 - A wrapper class in Salesforce is a custom Apex class that encapsulates and combines different data types or objects into a single unit. Itโ€™s essentially a container that allows developers to create a custom structure to hold related information ...
Top answer
1 of 2
1

Since you're new to programming, I'm going to give you more help than you asked for...

First, get your indentation under control. Messy code is hard to read. Almost every IDE has a way to make your code pretty. For VS Code, the Format Document function is your friend. For the Salesforce Developer Console, you can select all your code and use Shift+Tab to make it pretty.

Second, variable names can be 40 characters long. ctct means nothing, while contactName is expressive and clearly tells anyone reading your code what is meant by this. Don't be stingy with your variable names; this isn't the 1980s where you could only use variable names that were 2 letters long.

Third, I'd suggest you avoid using underscores in your LWC names; it makes it so you have to write awkward <c-store_detailz> for no good reason. Use TitleCase for class names, and camelCase for properties. Avoid using excessive uppercase letters, because something like MY_WONDERFUL_PROPERTY will have to be written as -m-y_-w-o-n-d-e-r-f-u-l_-p-r-o-p-e-r-t-y when used in a template, which is not very legible and a pain to type.

Fourth, your Apex can be shortened to just a few lines of code. Here's my rendition of your Apex code:

public class CurrentUserAndContactController {
  @AuraEnabled public static Map<String, String> theMethod() {
    User currentUser = [
      SELECT Contact.Account.Name, Contact.Name 
      FROM User 
      WHERE Id = :UserInfo.getUserId()
    ];
    return new Map<String, String> {
      'accountName' => currentUser.Contact.Account.Name,
      'contactName' => currentUser.Contact.Name
    };
  }
}

Using wrappers are fine, but when you're just getting started learning, keeping things simple is ideal.

Finally, four important things about JavaScript. First, JavaScript is case sensitive. That means that you absolutely need to make sure everything is capitalized correctly everywhere. Second, you need to pay attention to parameters. (Data, Error) is not the same as ({ data, error }). Third, when you reference a variable or function in a class, you always need to use this.. Fourth, you need to remember the structure of your data between the client and server. You tried to access aVar[0], but it should have been something like this.aVar.usr.

Here's my rendition of your controller, noting that I didn't change the component name only to keep things simple.

import { LightningElement, wire, track } from 'lwc';
import theMethod from '@salesforce/apex/CurrentUserandContactController.theMethod';

export default class Store_Detailz extends LightningElement {
    aVar;
    contact;
    user;
    
    @wire(theMethod) userDataHandler({data, error}) {
        if(data) {
            this.aVar = data;
            this.user = data.accountName;
            this.contact = data.contactName;
        }    
    }
}
2 of 2
0

JavaScript is case sensitive. Make sure you use the correct case. Salesforce returns to your wire handler function an object containing data and error properties, so these are the names you must use when destructuring the object. Change your code to:

    @wire(theMethod)
    aMtd({data, error}){
        if(data){
            this.aVar = data;
            this.user = this.aVar.usr;
            this.contact = this.aVar.ctct;
        }
    }

Note that I made sure that the data (stored into aVar - likely unnecessary) was assumed to be a WClass instance with the usr and ctct properties.

Find elsewhere
๐ŸŒ
Webkul
webkul.com โ€บ home โ€บ how to write a wrapper class in apex
How to use a wrapper class in APEX to store various types of values.
July 16, 2021 - The use of this variable will be explained later on in the code. For now, lets focus on the other parts. We have a list of productwrapper type and this list is being iterated over to check or uncheck the isActive field. One thing to notice here is that I have added all the record object to a list of product2 type. That is because DML does not work on Wrapper class and you have to take out the object to perform a DML operation on that object. ... <apex:page controller="wrappertest"> <apex:form> <apex:selectList value="{!selectedstatus}" size="1"> <apex:selectOptions value="{!status}"/> </apex:s
๐ŸŒ
Costco
costco.com โ€บ home โ€บ career opportunities
Career Opportunities | Costco
Our member service center employees respond to member phone calls and chats about memberships, Costco.com products and services, and other member inquiries. Service-minded individuals who remain calm under pressure, enjoy problem-solving, and have good typing skills do well at our member service centers.
๐ŸŒ
Interactiveties
interactiveties.com โ€บ blog โ€บ 2015 โ€บ apex-wrapper-class.php
Salesforce Wrapper Class Example
That's fine but if you're new to the concept then it is likely that the definition of a Salesforce wrapper class is not as useful as a practical example of the logic. Let's say that you want to build a simple Visualforce page that will display a list of Contacts. For the page you will require a controller similar to the following: /* Created by: Greg Hacic Last Update: 22 January 2015 by Greg Hacic Questions?: greg@interactiveties.com */ public with sharing class simpleController { public List<Contact> contacts = new List<Contact>(); //list for holding the Contact records to be displayed on th
๐ŸŒ
Salesforce
trailhead.salesforce.com โ€บ trailblazer-community โ€บ feed โ€บ 0D54V00007T4N1iSAF
Feed Item Detail | Salesforce Trailblazer Community
Skip to main content ยท Salesforce and Tableau exam registrations are now closed through July 21st. Learn more about the new Salesforce certification experience coming soon
๐ŸŒ
Salesforce Developers
developer.salesforce.com โ€บ docs
Developer Documentation | Salesforce Developers
Some examples include: cookies used for remarketing, or interest-based advertising.
๐ŸŒ
GradX Academy
gradxacademy.in โ€บ home โ€บ wrapper class in salesforce: a comprehensive guide 2023
Wrapper Class in Salesforce: A Comprehensive Guide 2023
August 8, 2023 - In LWC, you can use wrapper classes to bundle and process data retrieved from Apex controllers, making it easier to interact with the data within the component.
๐ŸŒ
GitHub
github.com โ€บ ccxt โ€บ ccxt
CCXT โ€“ CryptoCurrency eXchange Trading Library
June 1, 2026 - include "ccxt.php"; var_dump (\ccxt\Exchange::$exchanges); // print a list of all available exchange classes
Starred by 43.3K users
Forked by 8.7K users
Languages ย  Python 34.7% | C# 13.9% | Go 12.1% | TypeScript 11.1% | JavaScript 10.5% | Java 9.0%
๐ŸŒ
Martech Notes
martechnotes.com โ€บ what-is-a-wrapper-class-in-salesforce
What Is a Wrapper Class in Salesforce? - Martech Notes
April 1, 2026 - A Salesforce wrapper class is a user-defined Apex class used to group different data types together, typically so your controller can send a single, structured object to the UI (or return it from a method) instead of juggling parallel lists and maps.
๐ŸŒ
Scribd
scribd.com โ€บ document โ€บ 874536016 โ€บ Apex-Wrapper-Class
Apex Wrapper Class | PDF | Boolean Data Type | Data Type
A Wrapper Class in Salesforce Apex is a custom class that groups multiple objects or variables, allowing for the addition of extra information and creating user-defined data types.
๐ŸŒ
Ktema
ktema.org โ€บ articles โ€บ everyday-salesforce-patterns-wrapper-class
Everyday Salesforce Patterns: The Wrapper Class / David Reed
Every wrapper class looks a little different, because it's highly specific to the individual use case and Visualforce page. The overall pattern often looks rather like this example, which wraps either a Contact or a Lead in an inner class, called Wrapper, of the page controller.