Show Spinner in Salesforce LWC Headless Actions
Showing a spinner during headless Lightning Web Component Quick Actions helps improve user experience by providing immediate visual feedback during long-running asynchronous operations. The approach uses a reusable programmatic spinner modal component that blocks the UI and automatically closes once the Apex or UI Record API update completes. This prevents users from triggering duplicate actions and clarifies the processing status without requiring a standard modal UI. Developers can implement this pattern to enhance the usability and reliability of custom LWC Quick Actions handling complex data updates.
- Use a programmatic Lightning Modal to create a blocking spinner overlay during processing.
- Leverage a Promise to control modal lifecycle and auto-close after async work finishes.
- Invoke headless LWC Quick Actions with a spinner to prevent duplicate clicks and race conditions.
- Handle success and error with toast notifications after asynchronous updateRecord calls.
- Split spinner logic and business logic into separate reusable components for clarity.
How to Show a Spinner in Salesforce LWC Headless Actions ( lightning__RecordAction ) When implementing custom business logic in Salesforce Lightning Experience, developers frequently use Lightning Web Component (LWC) Quick Actions. One powerful approach is using a headless action (where actionType is configured as Action inside the lightning__RecordAction target). Unlike standard screen actions, headless actions run JavaScript code instantly without opening a default UI modal container. While headless actions provide a seamless UX for fast processing, long-running asynchronous processes—such as complex Apex calls or data manipulations via uiRecordApi —can leave users in the dark. Without immediate visual feedback, users may click the action button multiple times, causing race conditions or duplicate transactions. To solve this UX hurdle, you can utilize lightning/modal programmatically to build a clean, blocking processing spinner.