Salesforce List Controller – Standard and Custom List Controller
Job-ready Online Courses: Dive into Knowledge. Learn More!
1. Objective
In this Salesforce List Controller Tutorial, we are about to learn what does a List controller mean. Moreover, we will discuss how to build a Custom List Controller and using Standard Salesforce List Controller.
So, let’s start Salesforce List Controller.
Do you know about Salesforce Objects
2. What is Salesforce List Controller?
Salesforce list controller is nothing but a controller which assist and helps you to create Visualforce pages that can act on a set of records. For an instance all the pages in Salesforce that work with the set of records like list pages, mass action pages, and related lists. It is used for the following
- Account
- Campaign
- Asset
- Case
- Contract
- Lead
- Idea
- Opportunity
- Product2
- Order
- Solution
- Custom objects
- User
3. Building a Custom List Controller in Salesforce
A costume list controller and standard list controller are similar to each other. Costume list controller has the power to implement apex logic that is defined to act on the set of records.
public class opportunityList2Con { // ApexPages.StandardSetController must be instantiated // for standard list controllers public ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator( [SELECT Name, CloseDate FROM Opportunity])); } return setCon; } set; } // Initialize setCon and return a list of records public List<Opportunity> getOpportunities() { return (List<Opportunity>) setCon.getRecords(); } }
A costume list controller can also be created that uses anti- and semi-joins as one of the parts of SOQL query. It can be done in the following ways.
Have a look at Salesforce Environment
public with sharing class AccountPagination { private final Account acct; // The constructor passes in the standard controller defined // in the markup below public AccountPagination(ApexPages.StandardSetController controller) { this.acct = (Account)controller.getRecord(); } public ApexPages.StandardSetController accountRecords { get { if(accountRecords == null) { accountRecords = new ApexPages.StandardSetController( Database.getQueryLocator([SELECT Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Opportunity WHERE IsClosed = true)])); } return accountRecords; } private set; } public List<Account> getAccountPagination() { return (List<Account>) accountRecords.getRecords(); } }
The page that shows all these records uses a set of standard list controller actions, still, it all depends on iterating over the records returned.
<apex:page standardController="Account" recordSetVar="accounts" extensions="AccountPagination"> <apex:pageBlock title="Viewing Accounts"> <apex:form id="theForm"> <apex:pageBlockSection > <apex:dataList value="{!accountPagination}" var="acct" type="1"> {!acct.name} </apex:dataList> </apex:pageBlockSection> <apex:panelGrid columns="2"> <apex:commandLink action="{!previous}">Previous</apex:commandlink> <apex:commandLink action="{!next}">Next</apex:commandlink> </apex:panelGrid> </apex:form> </apex:pageBlock> </apex:page>
4. Using Standard List Controller
Action strategies perform logic or navigation once a page event happens, like once a user clicks a button, or hovers over an area of the page. Action strategies is referred to as from page markup by using notation within the action parameter of 1 of the following tags:
Do you know about Salesforce Export Data
|
So, this was all in the Salesforce List Controller. Hope you like our explanation.
5. Conclusion: Salesforce List Controller
In this Salesforce List Controller tutorial, we learned what does the term list controller in Salesforce means. Moreover, we discussed building a custom list controller and using standard list controller. still, if any doubt occurs, ask in the comment tab.
See also –
Role Hierarchy in Salesforce
For reference
Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google