Saturday 11 February 2012

StandardSetController


StandardSetController Class:

StandardSetController objects allow you to create list controllers similar to, or as extensions of, the pre-built Visualforce list controllers provided by Salesforce. The StandardSetController class also contains a prototype object. This is a single sObject contained within the Visualforce StandardSetController class. If the prototype object's fields are set, those values are used during the save action, meaning that the values are applied to every record in the set controller's collection. This is useful for writing pages that perform mass updates (applying identical changes to fields within a collection of objects).

Note:Fields that are required in other Salesforce objects will keep the same requiredness when used by the prototype object.
Keep in mind the following governor limits for batch Apex:
·         Up to five queued or active batch jobs are allowed for Apex.
·         A user can have up to five query cursors open at a time. For example, if five cursors are open and a client application still logged in as the same user attempts to open a new one, the oldest of the five cursors is released.
Cursor limits for different Force.com features are tracked separately. For example, you can have five Apex query cursors, five batch cursors, and five Visualforce cursors open at the same time.
§  A maximum of 50 million records can be returned in the Database.QueryLocator object. If more than 50 million records are returned, the batch job is immediately terminated and marked as Failed.
§  The maximum value for the optional scope parameter is 2,000. If set to a higher value, Salesforce chunks the records returned by the QueryLocator into smaller batches of up to 2,000 records.
§  If no size is specified with the optional scope parameter, Salesforce chunks the records returned by the QueryLocator into batches of 200, and then passes each batch to the execute method. Apex governor limits are reset for each execution of execute.
§  The start, execute and finish methods can implement only one callout in each method.
§  Batch executions are limited to one callout per execution.
§  The maximum number of batch executions is 250,000 per 24 hours.
§  Only one batch Apex job's start method can run at a time in an organization. Batch jobs that haven’t started yet remain in the queue until they're started. Note that this limit doesn’t cause any batch job to fail and executemethods of batch Apex jobs still run in parallel if more than one job is running.
You can instantiate a StandardSetController in either of the following ways:
·         From a list of sObjects:
·         List<account> accountList = [SELECT Name FROM Account LIMIT 20];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accountList);
·         From a query locator:
·         ApexPages.StandardSetController ssc =
new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name,CloseDate FROM Opportunity]));
Methods
StandardSetController methods are all called by and operate on a particular instance of a StandardSetController.
The table below describes the instance methods for StandardSetController.
Name
Arguments
Return Type
Description
cancel
System.PageReference
Returns the PageReference of the original page, if known, or the home page.
first
Void
Returns the first page of records.
getCompleteResult
Boolean
Indicates whether there are more records in the set than the maximum record limit. If this is false, there are more records than you can process using the list controller. The maximum record limit is 10,000 records.
getFilterId
String
Returns the ID of the filter that is currently in context.
getHasNext
Boolean
Indicates whether there are more records after the current page set.
getHasPrevious
Boolean
Indicates whether there are more records before the current page set.
getListViewOptions
Returns a list of the listviews available to the current user.
getPageNumber
Integer
Returns the page number of the current page set. Note that the first page returns 1.
getPageSize
Integer
Returns the number of records included in each page set.
getRecord
sObject
Returns the sObject that represents the changes to the selected records.This retrieves the prototype object contained within the class, and is used for performing mass updates.
getRecords
sObject[]
Returns the list of sObjects in the current page set. This list is immutable, i.e. you can't call clear() on it.
getResultSize
Integer
Returns the number of records in the set.
getSelected
sObject[]
Returns the list of sObjects that have been selected.
last
Void
Returns the last page of records.
next
Void
Returns the next page of records.
previous
Void
Returns the previous page of records.
save
System.PageReference
Inserts new records or updates existing records that have been changed. After this operation is finished, it returns a PageReference to the original page, if known, or the home page.
setFilterID
String filterId
Void
Sets the filter ID of the controller.
setpageNumber
Integer pageNumber
Void
Sets the page number.
setPageSize
Integer pageSize
Void
Sets the number of records in each page set.
setSelected
sObjects[] selectedRecords
Void
Set the selected records.






Example:
Controller Code:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public class opportunityList2Con {
// ApexPages.StandardSetController must be instantiated
// for standard list controllers
// Initialize setCon and return a list of records
List<Opportunity> opplst=[select name,closedate from opportunity];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(opplst);
public List<Opportunity> getOpportunities() {
return (List<Opportunity>) ssc.getRecords();
}
}

Page Code:
<apex:page controller="opportunityList2Con">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!opportunities}" var="o">
            <apex:column value="{!o.name}"/>
            <apex:column value="{!o.closedate}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
 =====
Output:
=============



No comments:

Post a Comment

How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...