Visualforce in Salesforce
Introduction
Visualforce is a framework that allows developers to build custom user interfaces in Salesforce. It
uses a tag-based markup language similar to HTML and integrates with Apex to provide dynamic and
interactive pages.
Key Features
Tag-Based Markup: Uses <apex:> tags to define components.
Integration with Apex: Allows interaction with Salesforce data.
Custom Styling: Supports CSS and JavaScript for enhanced UI.
Embedded in Lightning & Classic: Can be used within both UI experiences.
Security & Permissions: Respects user permissions and profiles.
Visualforce Components
Visualforce provides several standard components, including:
<apex:page>: Defines the Visualforce page.
<apex:form>: Creates a form to capture input.
<apex:inputText>: Accepts user input.
<apex:commandButton>: Executes actions.
<apex:pageBlock>: Creates sections with styling.
Example of a Basic Visualforce Page
<apex:page>
<apex:form>
<apex:pageBlock title="Hello Visualforce!">
<apex:outputText value="Welcome to Salesforce Visualforce!" />
</apex:pageBlock>
</apex:form>
</apex:page>
Visualforce with Apex Controller
Apex controllers handle backend logic for Visualforce pages.
Example:
Apex Controller:
public class HelloController {
public String message { get; set; }
public HelloController() {
message = 'Hello from Apex Controller!';
Visualforce Page:
<apex:page controller="HelloController">
<apex:outputText value="{!message}" />
</apex:page>
Advanced Topics
Custom Controllers & Extensions: Extend Apex logic for complex interactions.
Visualforce Remoting: Call Apex methods via JavaScript without reloading the page.
Embedding Visualforce in Lightning Components: Use <lightning:container> for integration.
Using Standard & Custom Objects: Work with Salesforce data dynamically.
Conclusion
Visualforce remains a powerful tool in Salesforce for creating customized interfaces and enhancing
user experience. With its deep integration with Apex and standard Salesforce functionality, it
provides flexibility for both classic and Lightning environments.