Select your Language

Wrapper Class

Wrapper class :
    ---------------
    1. It is a user-defined data type.
    2. It is also an apex class , Data structure , abstract data type whose instance is a collection of                 other object.
    3. It contains only data members .
    4. Wrapper class doesn't contain any methods .
    5. Wrapper class can contain simillar types and dis-simllar datatypes.
    6.  Wrapper classes are used to create custom datatypes .

 Example :
    public class Student{                 
    public String name;
    public String city;
    public String phone;
    }


Example
public class Account_Wrapper {
    public Account acc ;
    public Contact con;
    }



Example
use in Apex class

    List<Account_Wrapper>  accounts =new List<Account_Wrapper>();
    Account_Wrapper aw =new Account_Wrapper();
        aw.acc=new Account();
    aw.acc.Name='Wipro';
    aw.acc.Phone='123';
    aw.con=new Contact();
    aw.con.LastName='Myla';
    aw.con.FirstName='Satish';
    accounts.add(aw);


==> Create a map with account name as key and Opportunity as value
.
Map<String,Contact> accMap =new Map<String,Contact>();
for(AccountWrapper aw :accounts)
                {
accMap.put(aw.acc.Name,aw.con);
}

Scenario:

how can display a table of records with a check box and then process only the records that are selected.You can use wrapper class to display records from multiple records within a single table 
    

No comments:

Post a Comment