Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to customize the controller for Salesforce

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you the relevant knowledge about how to customize the controller in Salesforce. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

one。 Custom controller

Add a custom controller to the Visualforce page by referencing the name of the controller class in the controller properties. When our page uses a custom controller, we cannot use a standard controller. The page uses different properties to set the custom controller.

1. You can create a simple VF page through Developer Console and click File-- > New-- > Visualforce Page to create a Visualforce page.

The name of the page is called OPDSortManage

When we click Save when our page is edited, it will say that our Controller is not defined, so Xiao Meow suggests that you can create a Controller first and then create a page.

two。 You can create a simple custom controller through Developer Console and click File-- > New-- > Apex Class to create an Apex class

The class name needs to be the same as the class name of Controller referenced on our page.

The Getter method drags data from your controller onto your page. There are setter methods that allow you to submit values from the page to your controller.

Public with sharing class OPDSortManageController {public Integr Num {get;set;} / / Simulation variable get value set set value / / construct public OPDSortManageController () {num = 0;}}

Remember to save every time we change the code!

3. Switch back to our OPDSortManage page and save it again. This will prompt us to save successfully, if there are other errors, we need friends to review the code carefully.

4. Click Preview to open a preview of your page and you can view it as you make changes. You should open a new window with standard Salesforce page title and sidebar elements, but no content.

two。 Standard controller

"Visualforce uses the traditional Model-View-Controller (MVC) paradigm and includes complex built-in controllers to handle standard actions and data access, and provides simple and tight integration with Force.com databases. These built-in controllers are often called standard controllers, or even standard controllers.

This means that in order for the data in Salesforce to be displayed on the Visualforce page, you need a controller. The controller is the Apex class referenced in the Visualforce page. It is this controller that enables Visualforce pages to display Salesforce data on the page. The controller "gets" the data from the Salesforce and "sets" it on the Visualforce page.

The difference between a custom controller and a standard controller is that the standard controller already provides create, read, update, delete (CRUD) operations. And since most standard and custom objects already have standard controllers that can be used to interact with the data associated with that object, we don't need to write our own code for controllers.

We just need to use the line "standardController =" Account to reference the Visualforce page using the Account standard object. There is no Apex code here. This is very helpful because it means that we can take advantage of DataTables.js and Visualforce in a test or production environment without writing any Apex code.

three。 Extensibility controller

If you are an ignorant teenager, you may have written such a code ↓ like Xiao Meow.

Error code case:

Then, such code will give you an error when it is saved, which roughly means that a page cannot have both a StandardController standard controller and a Controller custom controller.

"controllers are controllers. Extensions are not controllers. The difference is that extensions cannot be placed on the page alone. In other words, extensions are not allowed unless there is a controller on the page first. Another remarkable feature is that the page allows only one controller. But you can add as many extensions as you need."

Correct case:

1. When we need to use both a standard controller and a custom controller, we can set the custom controller to be scalable

StandardController: standard controller

Controller: custom controller

Extensions: extensibility controller

Solution scheme can be deleted only if the status is in draft. Please click back to delete successfully. Click back.

two。 Custom controller

Public with sharing class Solution_ProgrammeDeleteController {public String ids {get;set;} public boolean is_Alert_Delete {get;set;} public Solution_ProgrammeDeleteController (ApexPages.StandardController controller) {ids = ApexPages.currentPage (). GetParameters (). Get ('id');} public void init () {Solution_Programme__c solutionProgrames = [select id, Status__c from Solution_Programme__c where id =: ids] If (solutionProgrames.Status__c.contains ('in draft')) {delete solutionProgrames; is_Alert_Delete = true;} else {is_Alert_Delete = false;}} above is all the content of the article "how to customize the controller for Salesforce". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report