function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sandeep kumar 44sandeep kumar 44 

alert massage before deleting record in trigger

hello all

i am working on a trigger in which i need to show an alret massege before deleting the record . how can i do it

            sale__c salesobj1=new sale__c();
            salesobj1=[select id from sale__c where];
            delete salesobj1;
            catch(exception e)

before salesobj1 gets deleted in need to show the alert massege to user and then let him save
kaustav goswamikaustav goswami
You cannot display an alert message from a trigger.

From trigger you can stop the deletion altogether based on your requirement. But you cannot provide the functionality of showing an alert message and then on click of okay carry out the delete operation.

If the user is trying to delete a record from the salesforce UI then generally an alert message(technically it is not an alert but a confirm message) is shown by Salesforce by defult.

Like this -

User-added image

You can throw the exception message to say "You need to confirm the deletion of this record before deleting by ticking 'Confirm Deletion' on the record" The user would then have to tick the "Confirm Deletion" tick box on the record and then try and delete the record again.
Anant KamatAnant Kamat
@Radnip, Can you provide some suggestions on implementing the user. I am kind of confused with your answer and trying to figure out