Lesson 3: Salesforce Development Advanced Concepts

Lesson 3: Salesforce Development Advanced Concepts


1. Visualforce Pages

  • Definition: Visualforce is a Salesforce framework for building custom user interfaces using HTML, CSS, and Apex.

  • Use: Create dynamic UI with Salesforce data.

  • Example: Display a list of accounts in a Visualforce page.

<apex:page controller="AccountController">
    <apex:pageBlock title="Account List">
        <apex:pageBlockTable value="{!accounts}" var="acc">
            <apex:column value="{!acc.Name}" />
            <apex:column value="{!acc.Industry}" />
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Explanation:

  1. <apex:page> binds the page to AccountController.

  2. <apex:pageBlock> organizes the UI layout.

  3. <apex:pageBlockTable> dynamically renders account data.


2. Lightning Web Components (LWC)

  • Definition: LWC is a modern framework for building Salesforce UIs with JavaScript, HTML, and Salesforce Apex integration.

  • Use: Develop responsive, high-performance UI components.

  • Example: LWC to display contact details.

HTML:

<template>
    <lightning-card title="Contact Details">
        <ul>
            <template for:each={contacts} for:item="contact">
                <li key={contact.Id}>{contact.Name} - {contact.Email}</li>
            </template>
        </ul>
    </lightning-card>
</template>

JS:

import { LightningElement, wire } from 'lwc';
import getContacts from '@salesforce/apex/ContactController.getContacts';

export default class ContactList extends LightningElement {
    @wire(getContacts) contacts;
}

Explanation:

  1. getContacts fetches data using an Apex method.

  2. <template> dynamically renders the contact list.

  3. @wire automatically synchronizes Apex data with the UI.


3. Apex REST APIs

  • Definition: Apex REST APIs enable external systems to interact with Salesforce using RESTful web services.

  • Use: Expose Salesforce data and actions.

  • Example: Create a custom REST API endpoint.

@RestResource(urlMapping='/AccountsAPI/*')
global with sharing class AccountsAPI {
    @HttpGet
    global static List<Account> getAccounts() {
        return [SELECT Id, Name FROM Account];
    }
}

Explanation:

  1. @RestResource exposes the class as a REST service.

  2. @HttpGet handles GET requests to retrieve data.

  3. SOQL fetches and returns Account data.


Summary

  • Visualforce Pages: Build custom user interfaces using Salesforce data.

  • Lightning Web Components: Create modern, responsive UIs.

  • Apex REST APIs: Integrate external systems using RESTful services.