function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VempallyVempally 

Wrapper List in Batch Apex...

Hi everyone,

I came across an interview quetion where I was asked to use a WrapList in Batch Apex.

How to do it...?
Agustina GarciaAgustina Garcia
The term "Wrapper List" is not something related to Batch Apex, so probably you would need to ask for more information about what they really want.

A Batch Apex is a feature that helps you to execute a process asynchronously. I'm just guessing but maybe they only want you create your own Iterabale class in order to be used in the Batch Apex. Find here (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_iterable.htm) an example. But really, I would ask for more information instead of doing something they don't expect.

Hope this helps.
Temoc MunozTemoc Munoz
A wrapper class is a class you implement to extend/protect the functionality of a Standard/Custom object.
The usual scenario where you need a Wrapper class is when you don't want to expose the objects you're using on a Visual Force Page.

Bad Practice:
<apex:Page controller="MyController">
   ....
  {!acct.Name} <!-- You have direct access to the sObject here -->
   ....
</apex:Page>

Best Practice:
<apex:Page controller="MyController">
   ....
  {!myWrapper.acct.Name} <!--Wrapper class provides an extra protection layer -->
  .....
</apex:Page>

Another scenario would be where you want to keep track of the records you want to save/delete etc. (i.e. a checkbox)
https://developer.salesforce.com/page/Wrapper_Class

In any case, you should always bulkify your processes, and having a List of wrappers is good practice. Thus, a "WrapList" is nothing more than a List of Wrappers.
 
List<MyWrapperClass> wrapList = new List<MyWrapperClass>();

The rest of the implementation depends on what they wanted from you in the interview.