Showing posts with label LWC Reusable Components. Show all posts
Showing posts with label LWC Reusable Components. Show all posts

Friday, June 19, 2026

LWC: Reusable Related List View

๐Ÿ“‹ Reusable Related List View for Salesforce LWC

A fully configurable Lightning Web Component that renders Salesforce related lists with pagination, sorting, search, inline editing, CSV export, row actions, and record management.

๐Ÿ“– Project Overview

relatedListView is a production-ready Salesforce Lightning Web Component designed to display related records dynamically without writing custom code for each object relationship.

The component is fully configurable through Lightning App Builder and supports pagination, server-side sorting, searching, CSV export, row actions, bulk selection, inline editing, and New/Edit record management.

Administrators can configure object names, parent relationships, columns, page sizes, and actions directly from App Builder, making the component reusable across multiple Salesforce implementations.

Reusable Related List View

✨ Key Features

Feature Description
Configurable Columns JSON-driven column configuration with labels, types, sorting, and editing support.
Pagination Supports 5, 10, 25, 50, and 100 record page sizes.
Server-Side Sorting ORDER BY support with persistent sorting across pages.
Search Debounced search filtering using SOQL LIKE queries.
Inline Editing Edit records directly inside lightning-datatable.
Row Actions View, Edit, Delete, and custom row actions.
CSV Export Export visible records to CSV format.
Bulk Selection Checkbox selection with event-based record handling.
New/Edit Modal Record creation and editing using lightning-record-edit-form.

๐Ÿ— Architecture

App Builder / Parent Component
            │
            ▼
     relatedListView
            │
 ┌──────────┼──────────┐
 │          │          │
 ▼          ▼          ▼
Header   Datatable  Pagination
Actions   Search     Controls
 │          │          │
 └──────┬───┴──────┬───┘
        ▼          ▼
  Record Modal  Delete Modal
        │
        ▼
RelatedListController.cls
        │
 ┌──────┴─────────────┐
 │                    │
 ▼                    ▼
getRelatedRecords()  getTotalCount()
        │
        ▼
 Dynamic SOQL Queries

๐Ÿ“ Project Structure

force-app
└── main
    └── default
        ├── classes
        │   ├── RelatedListController.cls
        │   └── RelatedListControllerTest.cls
        │
        └── lwc
            └── relatedListView
                ├── relatedListView.html
                ├── relatedListView.js
                ├── relatedListView.css
                └── relatedListView.js-meta.xml

README.md

⚙️ Lightning App Builder Configuration

Property Purpose
Object API Name Target child object.
Parent Field API Name Lookup relationship field.
Columns JSON Dynamic datatable configuration.
Page Size Records per page.
Enable Selection Show row selection checkboxes.

๐Ÿงฉ Column Configuration Example

[
  {
    "label": "Contact Name",
    "fieldName": "Name",
    "type": "text",
    "sortable": true
  },
  {
    "label": "Email",
    "fieldName": "Email",
    "type": "email"
  },
  {
    "label": "Phone",
    "fieldName": "Phone",
    "type": "phone"
  }
]

๐Ÿ’ป Component Usage Example

<c-related-list-view
    record-id={recordId}
    object-api-name="Contact"
    parent-field-api-name="AccountId"
    page-size="25"
    columns-json={columnConfig}>
</c-related-list-view>

๐Ÿ” Supported User Actions

  • View Record
  • Edit Record
  • Delete Record
  • Create New Record
  • Refresh Data
  • Search Records
  • Export CSV
  • Select Multiple Rows
  • Inline Save

๐Ÿ“ค CSV Export

The component can export currently visible records to CSV format while respecting configured columns and applied filters.

Header Actions
    │
    ▼
Export CSV
    │
    ▼
Generate Blob
    │
    ▼
Download File

๐Ÿ”’ Security Considerations

  • Uses with sharing Apex classes.
  • Supports Salesforce CRUD permissions.
  • Supports Field-Level Security.
  • Dynamic SOQL validation implemented.
  • Safe handling of configurable properties.

๐Ÿงช Testing

  • RelatedListControllerTest.cls included.
  • Pagination testing.
  • Sorting validation.
  • Search functionality verification.
  • CRUD operation testing.

๐Ÿš€ Deployment

sf org login web -a myOrg

sf project deploy start \
--source-dir force-app \
-o myOrg

๐ŸŽฏ Benefits

  • Eliminates custom related list development.
  • Highly reusable across multiple objects.
  • Admin-friendly configuration.
  • Modern Lightning user experience.
  • Improves productivity and maintainability.
  • Enterprise-ready architecture.

๐Ÿ“Œ Conclusion

The LWC Related List View component provides a complete replacement for traditional Salesforce related lists with advanced features such as search, pagination, inline editing, CSV export, row actions, and configurable columns. Its metadata-driven design makes it an ideal reusable solution for enterprise Salesforce applications.

Thursday, June 18, 2026

LWC: Collapsible Accordion

๐ŸŽฏ Collapsible Accordion for Salesforce LWC

A reusable, accessible, animated accordion component for Lightning Web Components with support for single-expand, multi-expand, slot-based composition, and programmatic control.

๐Ÿ“– Project Overview

Salesforce LWC Accordion is a fully reusable Lightning Web Component designed to create modern, responsive, and accessible accordion interfaces.

The component supports both single-expand and multi-expand modes, animated transitions, programmatic APIs, optional icons and badges, and slot-based content composition.

Whether you're displaying account details, forms, datatables, dashboards, FAQs, or complex business content, this accordion provides a flexible and scalable solution for Salesforce applications.

Salesforce-LWC-Accordion-Architecture-Diagram

Salesforce-LWC-Accordion

✨ Key Features

Feature Description
Single Expand Mode Opening one section automatically closes others.
Multi Expand Mode Multiple sections can remain open simultaneously.
Expand All / Collapse All Bulk control of accordion sections.
Smooth Animations CSS-based expand/collapse transitions.
Animated Chevron Visual indicator rotates automatically.
Slot-Based Composition Supports tables, forms, charts, and custom markup.
Data-Driven API Generate sections dynamically using JavaScript arrays.
Accessibility Ready ARIA-compliant and keyboard-friendly.

๐Ÿ— Architecture

Parent Component
        │
        ▼
c-accordion
        │
        ├── State Management
        ├── Multi Expand Logic
        ├── Programmatic API
        │
        ▼
c-accordion-section
        │
        ├── Header
        ├── Chevron
        ├── Badge
        ├── Icon
        └── Content Panel

๐Ÿ“ Project Structure

salesforce-lwc-accordion
│
├── README.md
│
└── force-app
    └── main
        └── default
            └── lwc
                ├── accordion
                │   ├── accordion.html
                │   ├── accordion.js
                │   ├── accordion.css
                │   └── accordion.js-meta.xml
                │
                ├── accordionSection
                │   ├── accordionSection.html
                │   ├── accordionSection.js
                │   ├── accordionSection.css
                │   └── accordionSection.js-meta.xml
                │
                └── accordionDemo
                    ├── accordionDemo.html
                    ├── accordionDemo.js
                    └── accordionDemo.js-meta.xml

๐Ÿ’ป Data-Driven Usage (Recommended)

<c-accordion
    title="Account Information"
    sections={mySections}
    allow-multi-expand={isMultiExpand}
    active-section-names={defaultOpen}
    onsectiontoggle={handleToggle}>
</c-accordion>

JavaScript Configuration

mySections = [
{
    name: 'details',
    label: 'Account Details',
    iconName: 'utility:account',
    content: 'Core account information.'
},
{
    name: 'contacts',
    label: 'Contacts',
    iconName: 'utility:people',
    badge: '5',
    content: 'Associated contacts.'
}
];

๐ŸŽจ Slot-Based Composition

<c-accordion-section icon-name="utility:opportunity" is-open="" label="Opportunity Summary" name="summary">
    <lightning-datatable columns="{columns}" data="{tableData}" key-field="id">
    </lightning-datatable>
</c-accordion-section>

⚙️ Programmatic Control API

Method Description
expandSection(name) Open a section programmatically.
collapseSection(name) Close a section programmatically.
getOpenSections() Returns all currently expanded sections.

Example

openContacts() {
    this.refs.myAccordion.expandSection('contacts');
}

logOpen() {
    const openSections =
        this.refs.myAccordion.getOpenSections();
}

๐Ÿ“ฆ Section Object Schema

{
    name: String,
    label: String,
    content: String,
    iconName: String,
    badge: String,
    isDisabled: Boolean
}

๐Ÿ“ข Events

Event Purpose
sectiontoggle Triggered whenever sections open or close.
toggle Fired by individual accordion sections.

♿ Accessibility Features

  • Native button-based interaction
  • aria-expanded support
  • aria-controls support
  • role="region" implementation
  • aria-disabled support
  • Keyboard navigation (Tab, Enter, Space)
  • Visible focus indicators
  • Screen reader friendly design

๐ŸŽจ CSS Custom Properties

c-accordion {
    --accordion-section-max-height: 600px;
}

๐Ÿš€ Deployment

sf org login web --alias my-org

sf project deploy start \
--source-dir force-app/main/default/lwc/accordion \
--source-dir force-app/main/default/lwc/accordionSection \
--target-org my-org

๐ŸŽฏ Benefits

  • Reusable across multiple Salesforce projects.
  • Supports both simple and complex content layouts.
  • Fully configurable using metadata and JavaScript.
  • Provides enterprise-grade accessibility.
  • Clean architecture with reusable APIs.
  • Smooth user experience with animations.
  • App Builder and Flow Screen compatible.

๐Ÿ“Œ Conclusion

Salesforce LWC Accordion is a flexible and accessible solution for creating collapsible content areas in Lightning Web Components. With support for data-driven configuration, slot-based content, animated transitions, and programmatic control, it can be used across a wide range of Salesforce applications while maintaining a clean and modern user experience.

Wednesday, June 17, 2026

LWC: Debug Log Viewer

๐Ÿ“‹ Debug Log Viewer for Salesforce LWC

View, filter, search, download, and manage Apex Debug Logs directly from Lightning Experience without opening Salesforce Setup.

๐Ÿ“– Project Overview

Debug Log Viewer is a reusable Salesforce Lightning Web Component that reads ApexLog records through the Salesforce Tooling API and displays them directly inside Lightning Experience.

Developers and administrators can inspect logs, search log contents, filter by event types, download log files, copy log content, and even bulk delete logs without navigating to Setup.

The solution uses Lightning Web Components, Apex, Tooling API integration, and Named Credentials to provide a modern debugging experience.

Debug Log Viewer Architecture

✨ Key Features

Feature Description
Debug Log Listing View ApexLog records in a Lightning datatable.
Filter Panel Filter by User Id, Operation, and Status.
Pagination Load logs incrementally in batches.
Log Detail Viewer Display full log content inside a dark-theme modal.
Category Filters Filter USER_DEBUG, SOQL, DML, and other log events.
Search Within Logs Quickly find keywords inside large log files.
Copy to Clipboard Copy raw or filtered log output.
Download Logs Save logs locally as .log files.
Bulk Delete Delete multiple Apex logs simultaneously.
Toast Notifications Success and error feedback for all operations.

๐Ÿ— Architecture

Lightning App / Utility Bar
│
├── debugLogViewer (Parent)
│
├── debugLogFilter (Child)
│
└── debugLogDetail (Child)
        │
        ▼
DebugLogViewerController.cls
        │
        ▼
Named Credential
        │
        ▼
Salesforce Tooling API
        │
        ├── ApexLog Query
        ├── Log Body Retrieval
        └── Bulk Delete Operations

๐Ÿ“ Project Structure

debug-log-viewer
│
├── force-app
│   └── main
│       └── default
│
├── lwc
│   ├── debugLogViewer
│   ├── debugLogFilter
│   └── debugLogDetail
│
├── classes
│   ├── DebugLogViewerController.cls
│   └── DebugLogViewerControllerTest.cls
│
├── namedCredentials
│   └── SalesforceToolingAPI
│
├── permissionsets
│   └── DebugLogViewer
│
└── README.md

⚙️ Core Components

Component Purpose
debugLogViewer Main orchestration component.
debugLogFilter Filtering UI for logs.
debugLogDetail Displays log body and search results.

๐Ÿ”Ž Supported Filtering Options

  • User Id
  • Operation Name
  • Status
  • Date Sorting
  • Event Type Categories
  • Keyword Search

๐Ÿ’ป Example Tooling API Query

SELECT Id,
       LogUser.Name,
       Operation,
       Status,
       DurationMilliseconds,
       LogLength,
       StartTime
FROM ApexLog
ORDER BY StartTime DESC
LIMIT 50

๐Ÿ“‚ Log Event Categories

USER_DEBUG
SOQL_EXECUTE_BEGIN
SOQL_EXECUTE_END
DML_BEGIN
DML_END
METHOD_ENTRY
METHOD_EXIT
EXCEPTION_THROWN

๐Ÿš€ Deployment

sf org login web \
--instance-url https://test.salesforce.com

sf project deploy start \
--source-dir force-app

๐Ÿ” Prerequisites

  • Salesforce CLI (sf)
  • API Version 59+
  • Sandbox or Developer Edition Org
  • Connected App
  • Named Credential
  • Tooling API Access

๐ŸŽฏ Benefits

  • No need to open Salesforce Setup.
  • Faster debugging workflow.
  • Centralized log management.
  • Bulk deletion support.
  • Developer-friendly user experience.
  • Modern Lightning UI.

๐Ÿ“Œ Conclusion

Debug Log Viewer modernizes the Salesforce debugging experience by bringing Apex log management directly into Lightning Experience. With filtering, searching, downloading, and bulk management capabilities, it significantly improves developer productivity and reduces dependency on Setup-based tools.

Tuesday, June 16, 2026

LWC: Reusable Modal

๐ŸชŸ Reusable Modal / Dialog for Salesforce LWC

Fully configurable, accessible, and reusable Lightning Web Component modal with named slots, multiple size variants, keyboard support, and customizable actions.

๐Ÿ“– Project Overview

Reusable Modal is a Lightning Web Component designed to provide a consistent modal dialog experience across Salesforce applications.

The component supports customizable headers, bodies, and footers through named slots while maintaining accessibility and Salesforce Lightning Design System (SLDS) compliance.

Developers can easily integrate the component into any Lightning Web Component and configure modal behavior using simple public properties.

Reusable Modal

✨ Key Features

Feature Description
Named Slots Custom header, body, and footer content.
Multiple Sizes Small, Medium, Large, and Full Screen variants.
Keyboard Accessibility Supports ESC key dismissal.
Overlay Click Close Optional backdrop click dismissal.
Default Footer Actions Built-in Cancel and Confirm buttons.
Fully Accessible ARIA support and SLDS compliant design.

๐Ÿ— Component Architecture

Parent Component
        │
        ▼
c-reusable-modal
        │
        ├── Header Slot
        ├── Body Slot
        ├── Footer Slot
        │
        ▼
Modal Controller
        │
        ├── Open / Close
        ├── ESC Handling
        ├── Confirm Event
        └── Overlay Click Logic

๐Ÿ“ Project Structure

force-app/main/default/lwc/

├── reusableModal/
│   ├── reusableModal.html
│   ├── reusableModal.js
│   ├── reusableModal.css
│   └── reusableModal.js-meta.xml
│
└── reusableModalDemo/
    ├── reusableModalDemo.html
    ├── reusableModalDemo.js
    └── reusableModalDemo.js-meta.xml

⚙️ Public API Properties

Property Default Description
isOpen false Controls modal visibility.
title '' Default modal title.
size medium small | medium | large | full
cancelLabel Cancel Cancel button text.
confirmLabel OK Confirm button text.
closeOnOverlayClick false Enable backdrop dismissal.

๐Ÿ“ Supported Modal Sizes

Size Description
Small~400px width
MediumSLDS default modal width
Large~90vw width
Full100vw × 100vh

๐Ÿ’ป Basic Usage Example

<c-reusable-modal cancel-label="Cancel" confirm-label="Delete" is-open="{isModalOpen}" onclose="{closeModal}" onconfirm="{handleDelete}" title="Confirm Delete">
    <span slot="body">
        Are you sure you want to delete this record?
    </span>
</c-reusable-modal>

๐ŸŽจ Custom Header, Body & Footer Example

<c-reusable-modal is-open="{isOpen}" onclose="{handleClose}" size="medium">
    <span slot="header">
        Warning
    </span>
    <span slot="body">
        Unsaved changes detected.
    </span>
    <span slot="footer">
        Custom Action Buttons
    </span>
</c-reusable-modal>

♿ Accessibility Features

  • role="dialog"
  • aria-modal="true"
  • aria-labelledby support
  • aria-describedby support
  • ESC key dismissal
  • Keyboard-friendly navigation
  • Accessible close button labels
  • SLDS-compliant focus management

๐Ÿš€ Benefits

  • Reusable across Salesforce projects.
  • Consistent user experience.
  • Improved accessibility.
  • Reduces duplicate modal code.
  • Easy integration into existing LWCs.
  • Supports enterprise-grade applications.

๐Ÿ“Œ Conclusion

Reusable Modal provides a clean, flexible, and accessible way to implement modal dialogs in Salesforce Lightning Web Components. With support for named slots, multiple size variants, keyboard interactions, and customizable behaviors, it serves as a foundational UI component for enterprise Salesforce applications.

Monday, June 15, 2026

LWC: Salesforce Toast Notification Framework

๐Ÿ”” Salesforce Toast Notification Framework

Reusable Lightning Web Component framework for displaying modern, customizable, and centralized toast notifications across Salesforce applications.

๐Ÿ“– Project Overview

Salesforce Toast Notification Framework provides a reusable and centralized approach for displaying success, error, warning, and informational notifications inside Lightning Web Components.

Instead of duplicating toast logic throughout an application, developers can dispatch a standardized event and allow the framework to render consistent notifications with configurable styling, positioning, icons, duration, and user interactions.

This project promotes better maintainability, cleaner component architecture, and a consistent user experience across Salesforce applications.

Salesforce Toast Notification Framework

✨ Key Features

Feature Description
Centralized Toast Management Single framework controls notifications across the application.
Multiple Variants Success, Error, Warning, and Information messages.
Custom Duration Configure auto-dismiss timing dynamically.
Stacked Notifications Supports displaying multiple toasts simultaneously.
Reusable Architecture Works across multiple Lightning pages and components.
Modern UI SLDS-inspired design with customizable styling.

๐Ÿ— Architecture

Application Components
        │
        ▼
Dispatch Toast Event
        │
        ▼
Toast Service / Utility
        │
        ▼
Toast Container
        │
        ▼
Toast Renderer
        │
        ▼
Success | Error | Warning | Info

๐Ÿ“ Project Structure

salesforce-toast-notification
│
├── force-app
│   └── main
│       └── default
│
├── lwc
│   ├── toastNotification
│   ├── toastContainer
│   ├── toastService
│   └── demoComponent
│
├── staticresources
├── permissionsets
└── README.md

๐Ÿ’ป Toast Event Example

this.dispatchEvent(
    new CustomEvent('showtoast', {
        detail: {
            title: 'Success',
            message: 'Record saved successfully.',
            variant: 'success'
        }
    })
);

⚙️ Toast Configuration

{
    title: 'Warning',
    message: 'Please review required fields.',
    variant: 'warning',
    duration: 5000,
    dismissible: true
}

๐ŸŽจ Supported Variants

✅ Success
❌ Error
⚠ Warning
โ„น Information

๐Ÿ”„ Notification Lifecycle

  1. User performs an action.
  2. Component dispatches toast event.
  3. Toast container receives notification.
  4. Toast is rendered with proper styling.
  5. User views notification.
  6. Toast auto-dismisses or closes manually.

๐Ÿงฉ Usage Example

<c-toast-notification>
</c-toast-notification>
import showToast from 'c/toastService';

showToast({
    title: 'Success',
    message: 'Account created successfully',
    variant: 'success'
});

๐Ÿš€ Benefits

  • Improves user experience.
  • Standardizes notifications across applications.
  • Reduces duplicated code.
  • Easy integration into existing LWCs.
  • Enterprise-ready notification management.

๐Ÿ“ฆ Deployment

sf org login web -a myOrg

sf project deploy start \
--source-dir force-app \
-o myOrg

๐Ÿ“Œ Conclusion

Salesforce Toast Notification Framework simplifies how notifications are managed within Lightning Web Components. By centralizing toast rendering and configuration, developers can deliver a consistent and maintainable user experience while reducing repetitive implementation effort.

Saturday, June 13, 2026

LWC: Apex Error Boundary

Apex Error Boundary

Centralized error handling pattern for Lightning Web Components with retry support, error categorization, and consistent user experience.

๐Ÿ“– Project Overview

Apex Error Boundary is a reusable Lightning Web Component pattern designed to centralize client-side error handling across Salesforce applications.

Instead of implementing duplicate error handling logic in every component, child LWCs simply dispatch a standard apexerror event when a wire adapter, imperative Apex call, or server operation fails.

The boundary component captures the error, categorizes it, displays a user-friendly UI, and optionally allows retrying failed operations.

Apex Error Boundary

✨ Key Features

Feature Description
Centralized Error Handling Single component handles all Apex and Wire errors.
Reusable Architecture Drop into any Salesforce project.
Retry Support Allow users to retry failed operations.
Technical Details Mode Optional expandable debugging information.
Error Categorization Converts raw Salesforce errors into user-friendly messages.
Event Driven Uses custom events for loose coupling.

๐Ÿ— Architecture Overview

Parent Page
│
└── c-apex-error-boundary
        │
        ▼
    Child Components
        │
        ├── @wire calls
        ├── Imperative Apex
        └── DML Operations
                │
                ▼
dispatchEvent('apexerror')
                │
                ▼
Boundary Captures Error
                │
                ▼
Error Classification
                │
                ▼
Friendly Error UI
                │
                ▼
Retry / Dismiss

๐Ÿ“ Repository Structure

apexErrorBoundary
│
├── classes
│   └── ExampleApexController.cls
│
├── lwc
│   ├── apexErrorBoundary
│   ├── apexErrorUtils
│   ├── exampleApexChild
│   └── accountRecordPage
│
├── staticresources
├── permissionsets
└── README.md

⚙️ Apex Controller Example

@AuraEnabled(cacheable=true)
public static Account getAccountDetails(Id accountId) {
    try {
        return [
            SELECT Id, Name, Industry
            FROM Account
            WHERE Id = :accountId
            LIMIT 1
        ];
    } catch (QueryException qe) {
        throw new AuraHandledException(
            'The account record could not be retrieved.'
        );
    }
}

๐Ÿ’ป Boundary Component Highlights

@api customTitle;
@api fallbackMessage;
@api maxRetries = 3;
@api showTechnicalDetails = false;
@api allowDismiss = false;

@track showError = false;
@track showChild = true;
@track isRetrying = false;

๐Ÿ”„ Runtime Error Flow

  1. Child component executes Wire or Apex call.
  2. Failure occurs.
  3. Component dispatches apexerror event.
  4. Error Boundary intercepts event.
  5. Error is parsed and categorized.
  6. User-friendly error message is displayed.
  7. User can retry the operation.

๐Ÿงฉ Usage Example

<c-apex-error-boundary custom-title="Account Information" max-retries="3" show-technical-details="true">
<c-example-apex-child record-id="{recordId}">
</c-example-apex-child>
</c-apex-error-boundary>

๐Ÿ“‚ Error Categories

  • Validation Errors
  • DML Exceptions
  • SOQL Query Failures
  • Permission Errors
  • Network Errors
  • Unknown Exceptions

๐Ÿš€ Benefits

  • Consistent UX across Salesforce applications.
  • Reduces duplicate error handling code.
  • Improves maintainability.
  • Simplifies debugging and support.
  • Provides enterprise-grade error management.

๐Ÿ“ฆ Deployment

sf org login web -a myOrg

sf project deploy start \
--source-dir force-app \
-o myOrg

๐Ÿ“Œ Conclusion

Apex Error Boundary provides a robust, reusable, and scalable solution for handling Salesforce Apex and Wire errors in Lightning Web Components. By centralizing error management, teams can improve user experience, reduce duplicate code, and simplify long-term maintenance.

Friday, June 12, 2026

LWC: Dynamic Form Builder

Dynamic Form Builder

Build and render forms dynamically using Lightning Web Components and Custom Metadata — no code changes required.

๐Ÿ“– Project Overview

Dynamic Form Builder is a reusable Salesforce Lightning Web Component that renders forms at runtime using either:

  • Custom Metadata configuration
  • JSON configuration

Administrators can create, modify, reorder, validate, and manage forms without redeploying code.


LWC Dynamic Form Builder

✨ Key Features

Feature Description
Dynamic Runtime Forms Generate forms without editing source code.
Custom Metadata Driven Store configuration inside Salesforce metadata.
JSON Support Render forms from inline JSON payloads.
Reusable Components Parent orchestrator + child renderer architecture.
Dynamic Submission Insert records using Apex Schema API.

๐Ÿ— Architecture

dynamicFormBuilder
│
├─ Loads configuration
├─ Manages validation
├─ Handles submission
├─ Emits events
│
└── dynamicFormField
      ├─ Renders correct component
      └─ Reports validity
Apex Controller
│
├─ getFormConfig()
└─ submitFormData()
Custom Metadata
│
├─ FormConfig__mdt
└─ FormFieldConfig__mdt

๐Ÿ“ Project Structure

dynamic-form-builder
│
├── force-app
│   └── main
│       └── default
│
├── classes
│   ├── DynamicFormBuilderController.cls
│   └── DynamicFormBuilderControllerTest.cls
│
├── lwc
│   ├── dynamicFormBuilder
│   └── dynamicFormField
│
├── customMetadata
│   ├── FormConfig
│   └── FormFieldConfig
│
└── README.md

⚙️ Supported Field Types

Text
Email
Phone
Number
Currency
Percent
Date
DateTime
Checkbox
Picklist
Lookup
Textarea

๐Ÿ’ป Example JSON Configuration

{
"title":"Contact Intake Form",
"columns":2,
"fields":[
{
"fieldName":"LastName",
"label":"Last Name",
"type":"text",
"required":true
},
{
"fieldName":"Department",
"type":"picklist"
},
{
"fieldName":"AccountId",
"type":"lookup",
"lookupObject":"Account"
}
]
}

๐Ÿš€ Quick Start

  1. Deploy project to Salesforce org.
  2. Open Lightning App Builder.
  3. Add Dynamic Form Builder component.
  4. Set Form Config Metadata Name.
  5. Activate page.
  6. Start rendering forms dynamically.

๐Ÿงฉ LWC Usage Example

<c-dynamic-form-builder

form-config-metadata-name="Contact_Intake_Form"

target-object-api-name="Contact">

</c-dynamic-form-builder>

๐Ÿ” Benefits

  • Metadata-driven UI
  • No redeployment for layout changes
  • Reusable architecture
  • Admin-friendly configuration
  • Scalable enterprise implementation

๐Ÿ“Œ Conclusion

Dynamic Form Builder provides a flexible way to build configurable forms in Salesforce using Lightning Web Components and Custom Metadata. It reduces maintenance effort and allows teams to manage form behavior directly from configuration rather than source code.

Thursday, June 11, 2026

LWC: Salesforce Field Set Renderer

Salesforce Field Set Renderer

Dynamically render Salesforce Field Sets in Lightning Web Components without hardcoding field names.

๐Ÿ“– Overview

Field Set Renderer is a reusable Salesforce Lightning Web Component that reads a named Field Set through Apex and dynamically renders fields at runtime. This approach eliminates hardcoded field references and allows administrators to control the UI simply by updating the Field Set configuration.

Salesforce Field Set Renderer

✨ Features

Feature Description
Zero Hardcoded Fields Field list is driven entirely by Field Set metadata.
View & Edit Modes Supports both lightning-record-view-form and lightning-record-edit-form.
FLS Aware Automatically respects field-level security permissions.
Required Validation Supports Field Set required and database required fields.
Configurable Layout Supports one-column and two-column layouts.
Lightning App Builder Ready Fully configurable through App Builder properties.

๐Ÿ— Architecture

FieldSetService.cls
        │
        ▼
Reads FieldSet Metadata
        │
        ▼
fieldSetRenderer (Reusable LWC)
        │
        ▼
View Mode / Edit Mode
        │
        ▼
Dynamic Salesforce Record Forms

๐Ÿ“ Project Structure

salesforce-fieldset-renderer
│
├── force-app
│   └── main
│       └── default
│           ├── classes
│           │   ├── FieldSetService.cls
│           │   └── FieldSetServiceTest.cls
│           │
│           └── lwc
│               ├── fieldSetRenderer
│               └── fieldSetRendererDemo
│
├── README.md
└── sfdx-project.json

⚙️ Apex Service Example

public with sharing class FieldSetService {

    public class FieldSetField {
        @AuraEnabled public String label;
        @AuraEnabled public String apiName;
        @AuraEnabled public String fieldType;
        @AuraEnabled public Boolean required;
        @AuraEnabled public Boolean editable;
    }

    @AuraEnabled(cacheable=true)
    public static List<FieldSetField> getFieldSetFields(
        String objectApiName,
        String fieldSetName
    ) {
        // Reads FieldSet metadata dynamically
    }
}

๐Ÿ’ป LWC Usage Example

<c-field-set-renderer
    record-id={recordId}
    object-api-name="Contact"
    field-set-name="Contact_Overview"
    mode="view"
    columns="2"
    onrecordsave={handleSave}
    oncancel={handleCancel}>
</c-field-set-renderer>

๐ŸŽฏ Public API

Property Description
recordId Salesforce record Id.
objectApiName API name of SObject.
fieldSetName Developer name of Field Set.
mode View or Edit mode.
columns 1 or 2 column layout.

๐Ÿš€ Deployment

sf org login web -a myOrg

sf project deploy start \
--source-dir force-app \
-o myOrg

๐Ÿ”’ Security & Permissions

  • Uses with sharing to respect record-level security.
  • Respects Field-Level Security (FLS).
  • Editable fields are automatically determined using Salesforce permissions.
  • Supports required field enforcement.

✅ Benefits

  • Reduces maintenance effort.
  • Admin-controlled UI configuration.
  • Reusable across multiple Salesforce objects.
  • Improves scalability and flexibility.
  • Ideal for dynamic forms and metadata-driven applications.

๐Ÿ“Œ Conclusion

Salesforce Field Set Renderer is a powerful reusable Lightning Web Component that dynamically renders fields based on Field Set metadata. By eliminating hardcoded field references, it enables administrators to manage layouts without code changes while maintaining security, flexibility, and scalability.

Wednesday, June 10, 2026

LWC: Custom Object Creator

LWC: Custom Object Creator

LWC: Custom Object Creator

This Salesforce project demonstrates how to create custom objects dynamically using Lightning Web Components (LWC) and Apex. It helps developers understand metadata-driven development in Salesforce.


LWC Custom Object Creator

✨ Key Features

  • Create Custom Object using LWC UI
  • Apex integration for metadata operations
  • Reusable architecture
  • Salesforce best practices implementation

๐Ÿ“ Project Structure


lwc-custom-object-creator/
│
├── force-app/
│   └── main/
│       └── default/
│           ├── classes/
│           │   └── CustomObjectController.cls
│           └── lwc/
│               └── customObjectCreator/
│
├── README.md
└── sfdx-project.json
    

⚙️ Apex Controller


public with sharing class CustomObjectController {

    @AuraEnabled
    public static String createCustomObject(String objectName) {
        // Logic to create custom object dynamically
        // Metadata API / Tooling API usage required
        return 'Custom Object Created: ' + objectName;
    }
}
    

๐Ÿ’ป LWC Component Example

HTML


<template>
    <lightning-card title="Custom Object Creator">
        <lightning-input label="Object Name" onchange={handleChange}></lightning-input>
        <lightning-button label="Create Object" onclick={handleCreate}></lightning-button>
    </lightning-card>
</template>
    

JavaScript


import { LightningElement } from 'lwc';
import createCustomObject from '@salesforce/apex/CustomObjectController.createCustomObject';

export default class CustomObjectCreator extends LightningElement {

    objectName;

    handleChange(event) {
        this.objectName = event.target.value;
    }

    handleCreate() {
        createCustomObject({ objectName: this.objectName })
            .then(result => {
                console.log(result);
            })
            .catch(error => {
                console.error(error);
            });
    }
}
    


๐Ÿ“Œ Conclusion

This project demonstrates how Salesforce developers can use LWC and Apex to build metadata-driven solutions. It is useful for learning dynamic object creation, platform APIs, and scalable architecture patterns.

LWC: Export & Import Multiple Custom Setting Records

LWC: Export & Import Multiple Custom Setting Records

LWC: Export & Import Multiple Custom Setting Records

This project demonstrates how to export and import multiple Custom Setting records in Salesforce using Lightning Web Components (LWC) and Apex integration.


Export & Import Multiple Custom Setting Records

✨ Features

  • Export Custom Setting records to CSV
  • Import records using file upload
  • Apex-based backend processing
  • Lightning Web Component UI
  • Reusable architecture

๐Ÿ“ Project Structure


Export-ImportMultipleCustomSettingRecordsUsingLWC/
│
├── force-app/
│   └── main/
│       └── default/
│           ├── classes/
│           └── lwc/
│
├── README.md
└── sfdx-project.json
    

⚙️ Apex Controller


public with sharing class ExportCustomSettingController {

    @AuraEnabled(cacheable=true)
    public static List getCustomSettings() {
        return new List{'Setting A', 'Setting B'};
    }

    @AuraEnabled
    public static String processFile(String fileContent) {
        // Logic to parse CSV and insert records
        return 'File processed successfully';
    }
}
    

๐Ÿ’ป LWC Component

HTML


<template>
    <lightning-card title="Custom Settings Export/Import">
        <lightning-button label="Export" onclick={handleExport}></lightning-button>
        <lightning-button label="Import" onclick={handleImport}></lightning-button>
    </lightning-card>
</template>
    

JavaScript


import { LightningElement } from 'lwc';

export default class CustomSetting extends LightningElement {

    handleExport() {
        console.log('Export triggered');
    }

    handleImport() {
        console.log('Import triggered');
    }
}
    


๐Ÿ“Œ Conclusion

This project helps Salesforce developers understand how to handle bulk data export/import using Lightning Web Components and Apex. It can be extended for Custom Metadata, Objects, or API integrations.