• LOGIN
  • No products in the cart.

Custom Controller in Salesforce

Online Training

Introduction:

Custom Controller can be defined as the Apex class, which is used to execute the page logic without using the regular controller. In order to make the visual force pages execute completely in the system, we must have to use custom controllers. In Salesforce, custom controllers include custom logic and data manipulation, which the page of Visualforce can use. Custom controllers fetch some items, and the visual force can use them as the controller. The customer controller is used to fetch the information or data that can be displayed on the page of visual force.

What is the need for a Custom Controller?

  • To include new actions.
  • A custom controller can be applied to overrule the regular controller embedded services.
  • To improve the pages of visual force that follow the permissions of the user.
  • Through the keyword “with sharing”, we can do role hierarchy, field-level security, and so on.
  • In the system model, the customs controller classes are implemented.

Types of Customer Controller:

  1. Custom Controller
  2. Standard Controller
  3. Controller Extension

1. Custom Controller: It is used to develop the customized functionalities, and all these can be replaced with available functionalities.

2. Standard Controller: It is used to interact with the structured business data presented in the Salesforce records.

3. Controller Extension: It is used to expand or include the services of the standard controller or a custom controller in Salesforce.

How to create a Custom Controller Apex Class?

Many of the system classes and utilities are available to improve the logic of custom controllers. In order to create a custom controller class, we must follow below steps:

  1. First, go to the Developer console and then press New/Apex class in order to establish the new apex class. Then name the class as “EmailidListController.”
  2. Now, open the editor and replace the code with the below program.

Public class EmailidListController {

Code

}

In Apex, when you make any changes, you must save them.

3. Then come to the page of Visualforce and save it.

4. In order to preview the page of Visual Page, the user must have to click the button of the preview. While making all those changes to the page, the user can use a page of visual force.

Related Tech Courses: Salesforce Integration Training

How to create a page of Visual force that uses a Custom Controller?

First, go to the console and then press New/Visual Page in creating the new visualforce page. Name the page as “EmailController.”

Then go to the editor and replace the markup with the below code:

<apex:page:controller=”EmailController”>

<apex:form>

< Apex: page block: Email Id List id =” Email Id_List”>

</apex:pageBlock>

</apex:form>

</apex:page>

Controller Methods:

Marking the Visualforce uses the below methods:

  1. Getter Methods
  2. Action Methods
  3. Setter Methods

Getter Methods: These are used to retrieve the values from the controller. Each of the values can be determined by the controller and can be exhibited in the page of visualforce must have a good method.

Here is an example, in the controller apex class, if we have a variable known as “account,” then it must have a method of “get an account” associated with it to access it via notation. Value argument present in the <APex:inputField> tag applies this notation to the account used to exhibit the account name.

Action Methods: These can be used to carry out logic or navigation when a page event happens, like a user clicking on the button and so on. Action methods are invoked via notation.

Setter Methods: These methods are used to send the controller’s particular values. These controller methods are executed before the action methods automatically get executed. 

Here is an example for you, if we want the markup for executing the search lead utility on the page, then the corresponding controller integrates the getter and setter methods for the search box input.

The controller uses the search text for sending a SOSL Query once the customer presses the button GO. The user must markup the implements the setter method before it is executing the method of search action. 

Salesforce is considered the market leader in the CRM space that provides a framework of web development known as Visualforce that enables the developers to establish the dynamic, sophisticated, and custom user interfaces hosted natively on the platform of force. It is known as the framework of component-based user interface that comprises markup the tag-based language and server-side set that is designed in simplifying the deployment and development of websites and cloud applications.

Few points to remember:

  • One Page Block has several Page Block Sections.
  • The tag has many attributes.
  • VisualForce Page has several page blocks.
  • One VisualForce Page has several tags.

VisualForce Page:

Having the powerful set of tags that are resolved at the server-side, the framework of VisualForce is called the model of a page-centric web application. Visualforce can be used as the markup language, which is very similar to the Apex code and designing pages to handle the database operations.

How can a Controller be used in the pages of Visualforce?

  • It accepts the information or data from the customers like the input values.
  • Controllers offer the business logic for the VisualForce pages.
  • Manipulated the data of the user that can be redirected to the browser as a new page.
  • Also, the controller manipulates the user’s input and performs an action in front of the customer. 

Now, let’s look at the VisualForce page classification:

Custom Controller: Apex code is used to handle the backend processing, which is implemented on the page of Visualforce.

VisualForce Pages: HTML, which is a markup language used for designing the page layout.

Apex Extensions: Logical operations are performed using the Apex extensions that are not available in the standard controllers.

JavaScript: JavaScript is used in managing the process of managing which is of the client-side, and it can also be coupled with CSS in revamping the interface.

Related Courses: Salesforce CPQ Training

What can we do with Custom Controllers?

  • Create new functionality
  • Use web services and HTTP callouts
  • Override existing functionality
  • Customize navigation
  • Control for how data is accessed on the page

Conclusion:

Custom controllers in Salesforce are used to implement the visualforce logic pages. The custom controllers have the methods in retrieving the information or data which is to be displayed on the page of visualforce. Feel free to contact Gologica or call: 8296960414 for more details about Salesforce.

GoLogica Technologies Private Limited. All rights reserved 2024.