Examples
Apex Visualforce Page
Building a Visualforce Page
Apex Visualforce page displays Contacts with a controller.
Introduction to Visualforce Pages
Visualforce is a framework that allows developers to build sophisticated, custom user interfaces that can be hosted natively on the Salesforce platform. These pages are similar to HTML but integrate seamlessly with Salesforce data.
Setting Up an Apex Controller
An Apex Controller is a class written in Apex that provides data and logic to Visualforce pages. For this example, we will create a controller to fetch and display a list of Contacts.
Below is an example of a simple Apex controller:
Creating the Visualforce Page
With the controller set up, the next step is to create the Visualforce page that will utilize this controller to display contacts. Here is the Visualforce page code:
Explanation of the Visualforce Page
The Visualforce page uses the ContactController
we created to fetch and display contacts. The <apex:page>
tag specifies the controller, and the <apex:pageBlockTable>
iterates over the contacts list, displaying each contact's name and email.
Testing the Visualforce Page
To test the Visualforce page, save your controller and page, then navigate to the Visualforce page URL in your Salesforce instance. Ensure you have contacts in your Salesforce instance to see the data being populated on the page.
Examples
- Previous
- REST Service
- Next
- LWC Component