I have an apex trigger on my custom object which will fire on record insertion or update (before insert before update). Based on certain criteria I would like to show users a modal.

Something like this:enter image description here

So users can click save or cancel and other actions will follow based on user decision. I wonder, is this somehow possible to fire that modal from my trigger, when user clicks on the save button of my custom object edit record page?

The edit and detail page of the record are standard pages, and i am not allowed to make custom Lightning pages to override them.

  • Why dont you override the edit page...?
    – Ayub
    Jun 27, 2018 at 11:47

4 Answers 4


It is not possible to fire user interface interaction from a trigger, except that throwing an exception in a trigger can result in surfacing an error in a UI context if there is one. For example, throwing an exception in a trigger that is fired due to a user's edit action in a standard page will show an error on that page. However, no further UI-based interaction with the trigger is possible, and all data updates made during the transaction are rolled back.

It is not possible to surface a modal from a trigger and engage in user interaction.

Since triggers run in both UI (Classic/Lightning) interactions and in backend (API/Process/Flow) actions, in many cases there is no UI at all.


If you really need a way for users using a Lightning app in the UI to receive some kind of notification when records are modified, even if they were modified by other users or via the API (bulk load, Data Loader, etc), it is possible to use Platform Events for that.

For example, we have a use case where we wanted certain Lightning components in our app to automatically refresh when the record they were dealing with gets updated, even if it got updated by other users or the API. To facilitate this, we have our trigger code publish a Platform Event that a "listener" (Lightning Component) in our app subscribes to, and then that listener fires a Lightning Application Event so that components in the app can recognize when records get updated, and act accordingly (in our case, refresh).

Platform Events are the only mechanism I found for letting Lightning components know that something happened to records as part of trigger logic.

  • There's a relevant Open source library that more-or-less demonstrates your solution. Nice work!
    – cropredy
    Jun 28, 2018 at 5:34
  • 1
    This is the correct answer, platform events subscribed by CometD will allow a lightning component to react to a trigger DML. Your trigger passes an event payload and your lightning component unloads and parses it.
    – tsalb
    Jun 28, 2018 at 6:24
  • Tankk you @Florissant53 for the explanation. Going to dig into platform events and hopefully find a solution. Also thanks to croperdy and tsalb also!
    – RSICK
    Jun 28, 2018 at 7:54
  • 1
    This is a really cool solution but it should be noted that it's one-way communication. You can't surface a modal interaction with which alters the operation of the trigger using Platform Events.
    – David Reed
    Jun 28, 2018 at 10:58

This should be done using a javascript controller using a custom component. Interactions with the user should be done using this method or flows.


It feels like you would like to stop or proceed with the update based on some criteria collected from a pop-up. Here are two ways:

  1. Block edit access to the field in question and let user update via a 'quick action' tied to a custom component that shows the pop-up and handles the update.
  2. Tedious way: Override the detail page completely with a custom lwc/aura page and shwo the pop-up

I don't think PEs should be used in this context mainly because they are meant for broad set of consumers(more so external, hence the comet-d bus) waiting for action within SF application.

  • If only required field or validation rule had a 'continue anyway' option! Jul 23, 2021 at 8:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .