Skip to main content

State Management

Explore practical guides and implementation patterns for this topic.

Posts

Agentforce

Mastering Salesforce Agentforce Variables: Explicit Memory for AI Agents

💬 In plain words: A variable securely stores a specific fact for the rest of an AI conversation. Without variables, you are blindly trusting the AI model to remember things accurately. By using variables, you lock that fact in place so it never drifts, hallucinates, or disappears.
Read article
Topic LWC
Lightning Web Components

How to Persist Selected Rows While Filtering a Salesforce LWC Datatable

In plain words: The standard Salesforce <lightning-datatable> has a major quirk: if a user selects a few rows, types a word into a search bar to filter the list, and then clears the search, their original selections disappear! To fix this, you must write custom JavaScript to temporarily store the IDs of selected rows that are "hidden" by the filter, and merge them back when the filter is cleared. Displaying data in a tabular format is a standard requirement for almost any enterprise application. In Salesforce Lightning Web Components (LWC), the lightning-datatable component makes this easy. However, combining row selection with dynamic front-end filtering introduces a frustrating state-management problem. Because filtering replaces the data bound to the datatable, any previously selected records that no longer match the search term are "forgotten" by the component. Let's walk through how to build a smart, stateful datatable that rem...
Read article
Topic LWC
Lightning Web Components

How to Keep LWC Datatable Rows Selected During Pagination

In plain words: When you use a paginated <lightning-datatable> in Salesforce, clicking "Next Page" completely refreshes the table's data. Because of this, any rows the user checked on Page 1 will be forgotten by the time they get back. To fix this, we must write custom JavaScript to save the IDs of selected rows into a "master list" behind the scenes, and then re-apply those selections every time the page changes. Displaying large datasets in Lightning Web Components (LWC) requires pagination to maintain performance. However, out-of-the-box, the lightning-datatable component does not remember selected rows when the underlying data changes. In this tutorial, we will build a custom datatable with "Previous" and "Next" pagination buttons that flawlessly remembers user selections across pages.
Read article