CRMSalesforce CRM

Salesforce Standard Controller

By June 24, 2020No Comments

When using Salesforce to retrieve information on pages and lists, a bunch of actions occur to make it happen.  This is done by built-in controllers behind the scenes.  When you open a record in Accounts View, the standard Account controller provides the data/functionality to the page which then formats it into what you see.  A controller can contain the logic to be executed when a button is clicked.

Most standard and all custom objects have standard controllers that can be used to interact with the data associated with it.  You don’t need to write the code for the controller yourself but you can extend the standard controllers to add new functionality, or create custom controllers from scratch.   Extensions are usually done in apex and require code coverage so it is suggested to use the Standard Controllers when you can.

Here’s how it works when creating a Visual Force Page to display object data:

The visual force page will begin with the controller you will be using.  This tells the page where to get the data from: <apex:page standardController=“Account”>

For this example we will use the Account object. The controller will look for an AccountID in the URL parameter and use that to retrieve data for the open record.  For example:  https://SalesforceInstance/lightning/r/Account/001D000000JRBes/view

The controller stores the data from the Account record in a variable to make them available to the page.  The variable will have the same name as the object; in this example, Account and it contains all of the fields available in Accounts.  When adding data to the page you refer to the individual fields by using the {!} wrappers with the <objectname>.<fieldname> like this: {!Account.Name }.  Be sure to include underscores and any __c extensions for custom fields.

You can use the standard controller to bring in related records too!  For example:  {!Account.Owner.Name}.  Notice the similarity of the syntax to when you query records using SOQL.

The Standard Controller will put the raw value directly on the page. To control the formatting of the value, you need to use a component that will take the raw value and format it appropriately.  See Creating a Visual Force Page for examples.

In addition to the data access, the standard controller provides a set of standard actions, such as create, edit, save, and delete. These can be added to your pages using buttons and links.

 

 

 

 

 

 

Becci MG

Author Becci MG

More posts by Becci MG

Leave a Reply

Questions about Salesforce?


Email Gene directly at gene@marksgroup.net!

EMAIL GENE NOW