Salesforce is a cloud-based CRM, which provides different Solutions such as Sales Cloud, Service Cloud, Marketing Cloud. It offers applications for small, midsize and enterprise business. Salesforce provides Workflows, Process builders, Approval process and so on to customize the functionality according to our business requirement. It also provides Apex and Visualforce to customize the Salesforce UI. Now, we are going to see different types of Controllers in Salesforce and their usage.
It also has a mobile app. Custom apps can be built for Android and IOS which can be directly listed in the App Stores. Salesforce can be integrated with ERP systems such as SAP B1, SAP ECC, and Nav Dynamics, E-commerce such as Magento.
Model View Controller
A Visualforce page in Salesforce is composed of Components and Controllers and it follows Model-View-Controller (MVC) architecture. In MVC Visualforce page acts as the View, Database acts as Model and the functionality to be implemented is the Controller. In MVC we can easily separate the view from Controller and Database.
The Controller acts as a mediator between View and Model. It communicates with the model and provides the data requested by the view and it also sends the data back from Visualforce Page to Database. It defines the flow of data between Model and View.
A controller provides business logics to Visualforce pages, takes the input, manipulate the data and sends the data to the Visualforce page. It can also update the data to the database. It specifies what is the action to be performed when a button or link is clicked on a Visualforce page.
There are 3 types of Controllers in Salesforce. They are listed below.
-
- Standard Controllers
- Custom Controllers
- Controller Extensions
Now let us look at each of these controllers in details.
Standard Controllers:
By default, all the Salesforce objects which can be queried by Lightning Platform API has Standard Controllers. It works similar to that of a standard Salesforce page. All the Validation rules exist in Standard controller can be applied in the Visualforce page that is using the standard controller. The Visualforce page inherits the style from the standard salesforce page associated with the specific Object. We can also override the style of a page that uses the standard controller.
In a Standard Controller, the id of the record to be retrieved is provided in the page URL. It has a ‘getter’ method, which returns the data of the specific record. The user cannot access the data in the Visualforce page if the user doesn’t have access to the object provided in the Standard Controller.
Standard Controller support multiple actions to perform logic when an event occurs. Below are the list of action methods and their functionality:
Action | Description |
Save | Inserts a new record or updates an existing record if it is currently in context. After this operation is finished, the save action returns the user to the original page (if known), or navigates the user to the detail page for the saved record. |
Quicksave | Inserts a new record or updates an existing record if it is currently in context. Unlike the save action, this page does not redirect the user to another page. |
Edit | Navigates the user to the edit page for the record that is currently in context. After this operation is finished, the edit action returns the user to the page where the user originally invoked the action. |
Delete | Deletes the record that is currently in content. After this operation is finished, the delete action either refreshes the page or sends the user to tab for the associated object. |
Cancel | Aborts an edit operation. After this operation is finished, the cancel action returns the user to the page where the user originally invoked the edit. list Returns a PageReference object of the standard list page, based on the most recently used list filter for that object. For example, if the standard controller is contact, and the last filtered list that the user viewed is New Last Week, the contacts created in the last week are displayed. |
List | Returns a Page Reference object of the standard list page, based on the most recently used list filter for that object. For example, if the standard controller is contact, and the last filtered list that the user viewed is New Last Week, the contacts created in the last week are displayed. |
Standard List Controllers
In the standard controller, we are allowed to work only on one record which is provided in the URL. In the Standard List Controller, we are allowed to work on a list of records. By default, all the records returned are sort on the first column of data when a standard list controller is used. All the list-views associated with the Salesforce page can also be included in the standard list controller. Multiple records can also be edited at the same time with a standard list controller.
Similar to Standard Controller, standard list controller also supports multiple actions to perform logic when an event occurs. Below are the list of action methods and their functionality:
Action | Description |
save | Inserts new records or updates existing records that have been changed. After this operation is finished, the save action returns the user to the original page, if known, or the home page |
quicksave | Inserts new records or updates existing records that have been changed. Unlike the save action, quicksave does not redirect the user to another page.
list Returns a PageReference object of the standard list page, based on the most recently used list filter for that object when the filterId is not specified by the user |
Cancel | Aborts an edit operation. After this operation is finished, the cancel action returns the user to the page where the user originally invoked the edit |
First | Displays the first page of records in the set |
last | Displays the last page of records in the set |
next | Displays the next page of records in the set |
previous | Displays the previous page of records in the set |
Using the right controller
We have seen the standard controller and standard list controller. The standard controller will be used when you want to work on a single record whereas, standard list controller is used when a mass action needs to perform. We will be discussing the Custom Controllers and Controller extensions in the next post.
How we can help
Our team can help you customize and integrated Salesforce as per your business process. Read about our Salesforce Integration Services. Reach out to us for a free assessment of your business needs.