29
NovBlack Friday Deal : Up to 40% OFF! + 2 free self-paced courses + Free Ebook - SCHEDULE CALL
The best career you can have today in the world of IT is in Salesforce. It is one of the greatest CRM software in the world. Also, it is growing, and there is no looking back. However, there are many steps and aspects of learning Salesforce. Controller extension is one significant part of the Salesforce.
Let us take this in detail.
It is always better to know something at length, its benefits and how will it be helpful to you in your career graph. It is also important to know how to make most of your time to learn the most important parts so that you get the right opportunities. Even when you are mid-way in your career and looking for the next step in your career, you will be required to upgrade your knowledge and skills.
In this blog, the idea is to take you about the controller extensions and everything around them so you have a better picture of them before you actually make your mind to dig deeper into these.
Let us begin by finding out what are these controllers.
Controllers in Salesforce are employed in defining both the data and the actions for the various VisualForce pages. They are typically used for accessing different types of objects through the APIs. These are different from the extensions. Where the custom controllers are used for containing all the data and actions in a particular page that has to be executed at a future time, the extensions let the data auctioned that is already present as buttons, custom overrides, links, etc. Also, if you make use of the Properties while you use controllers, it will help you to highly difficult code for a long time without any interruptio, s and also you will not be required to go through any kind of clutter while you review the code.
The standard controllers in Salesforce are the ones that help in your interaction with the VisualForce pages. As the name suggests it is the real ‘standard’ or the point from which you start making use and even implement the true functionality of the standard or any custom object viz. the Account or the <TestObject>_c object.
These come endowed with many inbuilt functionalities. Save, Edit, Delete, and Cancel, etc. are some of the standard actions that are available in these types of controllers.
The standard list of controllers is often needed for displaying a complete list of records in the Salesforce VisualForce. These are thus, used for leveraging the basic or the default behaviour of objects like the clone, save, delete, edit in addition to many other basic methods or other properties that are present in those objects.
These controllers are also useful in accessing the Child Objects, that lie one step below in the hierarchy, like Contact to Account, etc.
Many pagination options like Fast, Like, Previous and even Next are also available. All these are highly similar to other Standard Controllers except the recordSetVar.
Read: Salesforce Admin Salary Trends in 2024 | How much do Salesforce Admins Earn
In a basic initialization of the controller for various objects, <sObject> is often accepted as a parameter. Thus, once the object is there it becomes important to leverage it by making use of the following section of initialization of the standard controller.
<sObject> obj = (<sObject>) std.getRecord();
Herein, the <sObject> has to be replaced by the kind of sObject that you are handling in that particular case.
The syntax for these controllers can be in form of the following:
Syntax: <apex:page standardcontroller="account" recordsetvar="accounts">
The VisualForce pages that make use of the declaration of the standard controller, are also used as the custom buttons on the objects by joining them on the VisualForce page that has been defined. Also, to avoid a standard button in an object like the New, Edit, Delete, etc. the defined VisualForce Page has to make use of the standard controller of the object.
It has to be noted that a particular case of using a Standard Set/List Controller is linked with buttons on the ListViews. This is typically the case when the getRecords() returns a particular list of objects and getSelected () will then return a list of the ones that have been selected before by making use of the checkboxes that lie next only to the records in a typical list view.
Some of the most known uses of the Standard Controllers are for adjustment of the default object landing pages, custom and List view functionality, inline pages, etc.
Apart from the standard controllers, there are the custom controllers in Salesforce. They are the ones that take on the functionality of the Standard Controller and also allow access to extra information:
These controllers are basically used for the implementation of the Custom Logic with the VisualForce pages. Custom controllers also allow the possibility of the creation of new functionalities.
The experienced developers often resort to custom controllers as and when they need additional complexity and some kind of new behavior. This often happens at the cost of the use of a standard controller. This is often used when one is thinking of the next types of the controller as an add-on strategy.
Read: Salesforce Tutorial - Ultimate Learning Guide for Beginners & Beyond
The syntax for these controllers is
Syntax: <apex:page controller="account">
Controller extension basically refers to a specific class of APEX with the extended functionality of both the custom and standard controller. These ultimately make way for you to consolidate the functionalities of both the controllers by extension as it allows for more than one extension for a particular Custom or a Standard controller.
Controller extensions can be used in multiple scenarios like the following:
You have to remember that although it is possible to add extensions to any kind of controller, you still have to make a choice between the Standard Controller or the Custom Controller but not both, while you are declaring a particular page. However, you can use many extensions as desired if you really want to extend the functionality.
The Controller extensions can also be used for overriding various kinds of permissions. This is possible because it is possible for the extension class to possess a setting for different sharing than the one that is inherited.
It becomes important for you to keep in mind that the extensions extend the basic standard custom controller. Thus, every extension will accept the Standard or the Custom Controller as a different parameter to the constructor as shown below:
public class myControllerExtension {
private final Account acct;
// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller
public myControllerExtension(ApexPages.Standard Controller stdController) {
this.acct = (Account) stdController.getRecord();
}
public String getGreeting() {
return 'Hello ' + acct.name + ' (' + acct.id + ')';
}
}
You have to remember that it is vital for you to make use of the initialization like
(<sObject>)stdController.getRecord();
for accessing the real object that the extension is working for.
Hence, the controller extensions are basically the best of both the worlds for using the standard and the custom controller functionality and further extend them. It allows for a much more reusable and a modular kind of approach and even the design.
Now that you have realized and know in detail about the different types of controllers, it is also essential to find out when is the best time for using each of them.
Read: What is Test Classes in Apex Salesforce?
In all of these, one thing gets underlined and that is the same functionality has to be used again for multiple pages. You also have to ensure that you use the same controllers for avoiding the duplication of the same kind of functionality. The same controller can be used over more than one page.
Now that everything seems settled, let us also walk through some deeper lanes in the Standard controller and see how they actually work to access data.
A Standard Controller usually makes use of a getter method for accessing the data. The method is said to return the particular record that has been marked by the id query string parameter in the URL of the page.
This method is successful only when the record that is marked in the specific id query string parameter in the URL is of the same form as is the standard controller.
It allows you to walk up to five levels of the child-to-parent relationship like if you are making use of the contact standard controller then you can use the {! contact.Account.Owner.FirstName} shows a three-level child-to-parent relationship for returning the name of the owner of the account record that is linked with the contact.
Also, you can also walk up to one level of the child-to-parent relationship like if you are using the Account standard controller then you can use the {!account. Contacts} for returning an array of all the contacts that are linked with the particular account in question.
Every time a page event takes place, the action methods help in performing logic and navigation like when a user hits on a button or simply visits a particular area of the webpage. All the action methods are actually called from the page markup by using {! } notation in the various action parameters of the following tags.
Summary
Every new step in life is based on the choice we make. These little choices although small usually pave the way for something really big in life. Salesforce is the real future of the online sphere as it is spreading its wings to different areas. It is the way things are handled at every step that will help you in your life. Hence, Salesforce has many aspects that have to be studied at length to grow in the organization. Everything matters and has to be considered. These were some of the important pointers about the controllers in Salesforce. Knowledge of these is essential and has to be well-taken. Do let us know how far it was useful for enhancing your knowledge so we may keep bringing more of these to you.
Read: Top 125 Visual Salesforce Interview Questions and Answers For Freshers and Experienced
A dynamic, highly professional, and a global online training course provider committed to propelling the next generation of technology learners with a whole new way of training experience.
Cyber Security
QA
Salesforce
Business Analyst
MS SQL Server
Data Science
DevOps
Hadoop
Python
Artificial Intelligence
Machine Learning
Tableau
Search Posts
Related Posts
What is Salesforce Workbench? Salesforce Workbench Tutorial Guide 296.5k
A Detailed Guide on Salesforce Business Analyst Roles & Responsibilities in 2024 14.7k
How to Prepare For Salesforce Developer Interview Questions?-Tips and Tricks? Beginners Tips! 380.5k
Who Wins The Battle Between Pipedrive And Salesforce? 670.7k
A Comprehensive Guide for Salesforce Certification Preparation 237.4k
Receive Latest Materials and Offers on Salesforce Course
Interviews