+ Start a Discussion
Michael Haddad.ax365Michael Haddad.ax365 

Can Apex pop up an Alert Box?

Hi

I am using a simple Apex trigger to prevent the insertion and updating of certain records when they are duplicates and meet a few other criteria.  This is simple enough.  I basically copied the example out of the Force.com Cookbook for preventing the insertion of Leads with duplicate E-mail addresses.

There are a few cases where my client would like duplicate insertion and updating allowed, but to be preceeded by a simple alert nortification (similar to Javascript's alert).  Is there a way to do this with Apex?

Thanks!

Michael
Best Answer chosen by Admin (Salesforce Developers) 
gsickalgsickal

No, Apex is a server side scripting language.  To popup an alert (in the client) you need to do this in a client side scripting language such as Javascript (or scontrols).  What you need to do is to have an scontrol call and invoke your Apex code and then if you want to display an alert, the Apex code would need to return some sort of message back to the scontrol client that called it and then the scontrol can display this message in a normal alert box.

If you then need to continue on processing in Apex you will need to call a new method in Apex at that point, so you might want to consider this when designing your Apex classes and try to minimize the need for displaying messages...