Problem :- How can I display a table of records with a check box and then process only the records that are selected?
Solution:- Wrapper class.
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
public with sharing class WrapperDemoController {
public List<AccountWrapper> listAccountWrapper {get; set;}
public List<Account> selectedAccounts{get;set;}
public WrapperDemoController ()
{
listAccountWrapper = new List<AccountWrapper>();
searchRecord();
}
public void searchRecord()
{
listAccountWrapper.clear();
for(Account a: [select Id, Name,BillingState, Website, Phone ,Active__c from Account limit 10])
{
listAccountWrapper.add(new AccountWrapper(a));
}
}
public void processSelected()
{
selectedAccounts = new List<Account>();
selectedAccounts.clear();
for(AccountWrapper wrapAccountObj : listAccountWrapper)
{
if(wrapAccountObj.selected == true)
{
selectedAccounts.add(wrapAccountObj.acc);
}
}
}
public void ActivateData()
{
for(Account acc : selectedAccounts )
{
acc.Active__c ='Yes';
}
update selectedAccounts ;
searchRecord();
}
public void DeActivateData()
{
for(Account acc : selectedAccounts )
{
acc.Active__c ='No';
}
update selectedAccounts ;
searchRecord();
}
// This is our wrapper/container class.
public class AccountWrapper
{
public Account acc {get; set;}
public Boolean selected {get; set;}
public AccountWrapper(Account a)
{
acc = a;
selected = false;
}
}
}
Wrapper class is a class that "wraps" or "encapsulates" the functionality of different data types. A wrapper class can be collection of different data types (Integer, String, Byte, Boolean, SObject ets..)
1) http://amitsalesforce.blogspot.in/2016/03/wrapper-class-in-salesforce-select-all.html
Problem :-
How can I display a table of records with a check box and then process only the records that are selected?
Solution:-
Wrapper class.
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 Page
Let us know if this will help you
Thanks
Amit Chaudhary
https://success.salesforce.com/answers?id=90630000000hSoLAAU
http://www.sfdcpoint.com/salesforce/wrapper-class-in-apex/
Thanks,
Veera
A wrapper class can be collection of different data types (Integer, String, Byte, Boolean, SObject ets..)