UI Development

Apex Visualforce

Using Visualforce

Apex Visualforce builds custom UIs with controllers.

Introduction to Visualforce

Visualforce is a powerful framework that enables developers to build sophisticated, custom user interfaces in Salesforce. It leverages the full potential of the Salesforce platform by allowing developers to integrate tightly with the Salesforce data model and business logic capabilities.

Visualforce pages are built using a combination of Visualforce markup and Apex controllers. This allows for the creation of dynamic, data-driven web pages that can interact with Salesforce records and business processes.

Visualforce Markup Language

Visualforce markup is similar to HTML in structure but includes Salesforce-specific components and tags. These components allow developers to incorporate Salesforce features directly into their pages. Visualforce pages are saved with a .page extension.

Apex Controllers

Apex controllers are used to handle the logic behind Visualforce pages. They interact with the database, perform calculations, and enforce business logic. There are two types of controllers:

  • Standard Controllers: Automatically provided by Salesforce for standard and custom objects.
  • Custom Controllers and Controller Extensions: Custom-written in Apex to provide additional functionality or override standard behavior.

Integrating Visualforce with Apex

Integrating Visualforce with Apex involves binding Visualforce components to Apex controller properties and actions. This tight integration allows for a seamless flow of data and user interactions.

In the example below, the greetUser method from the Apex controller is invoked when the command button is clicked, demonstrating how user actions on the UI can trigger complex business logic.

Best Practices for Visualforce Development

When developing with Visualforce, it's important to follow best practices to ensure efficient, maintainable, and scalable applications:

  • Utilize standard components wherever possible to maximize compatibility and performance.
  • Keep logic within Apex controllers rather than Visualforce pages to maintain separation of concerns.
  • Use custom controllers when advanced logic is necessary, but avoid unnecessary complexity.
  • Regularly test your Visualforce pages to ensure they are functioning as expected.

UI Development

Previous
Tooling API