Use Case: Modular and Generic LWC components

Creating modular and generic Lightning Web Components (LWCs) for a community portal in Salesforce, including features like custom toast notifications, CRUD operations, dynamic tables with inline edit, and filters, involves building reusable components that can be easily configured and integrated into various parts of the portal. Here’s how you can approach each aspect:

1. Custom Toast Notification Component

  • Purpose: To display notifications for various actions (success, error, warning) across different parts of the community portal.

Implementation Steps:

  • Create a <c-toast> component:
    • Accept parameters such as message type (success, error, warning), message content, and duration.
    • Use SLDS (Salesforce Lightning Design System) classes for styling and animations.
    • Implement a method to trigger the toast from parent components or from Apex methods.
    • Ensure it’s dismissible by users.

2. CRUD Operations Component

  • Purpose: To perform Create, Read, Update, Delete operations on Salesforce data objects (e.g., Accounts, Contacts).

Implementation Steps:

  • Create a <c-record-form> component:
    • Dynamically generate input fields based on object metadata or fields passed as attributes.
    • Implement methods for CRUD operations using Apex controllers or Lightning Data Service.
    • Handle error messages and display them using <c-toast> component.

3. Dynamic Tables with Inline Edit and Filters

  • Purpose: To display data in tabular format with the ability to edit records inline and apply dynamic filters.

Implementation Steps:

  • Create a <c-dynamic-table> component:
    • Accept parameters for columns (field API names, labels, types) and data (list of records).
    • Implement inline editing using <lightning-input> or <lightning-combobox> components.
    • Include filter components (<c-dynamic-filter>) for each column type (text, picklist, date).
    • Use JavaScript functions to handle sorting, pagination, and filtering client-side.
    • Implement save and cancel actions for inline edits.

Integration and Usage in Community Portal:

  • Modularity: Each component should be designed to be reusable and configurable.
  • Dependency Management: Use events and attributes to facilitate communication between parent and child components.
  • Styling: Ensure consistency with Salesforce Lightning Design System (SLDS) for a cohesive look and feel.

Example Scenario:

  • Objective: Display a list of Opportunities with inline editing capability and filters by Opportunity Name, Stage, and Close Date.

  • Implementation:

    • Use <c-dynamic-table> component with columns configured dynamically based on Opportunity fields.
    • Implement <c-dynamic-filter> components for each filter criterion.
    • Use <c-record-form> for inline editing, updating Opportunity records.


  • Performance: Optimize data retrieval and processing, especially when dealing with large datasets.
  • Security: Implement field-level security and data validation to prevent unauthorized access and ensure data integrity.
  • User Experience: Design intuitive interfaces with clear feedback mechanisms (toasts, error messages) for better user engagement.

By following these steps and considerations, you can create modular and generic Lightning Web Components for a community portal in Salesforce, enhancing flexibility, scalability, and usability across different use cases and functionalities.

Leave A Comment

All fields marked with an asterisk (*) are required