+ Start a Discussion

Injecting javascript in apex trigger


I'm a newbie in APEX. I would like to ask if it's possible to add a javascript inside a trigger. Say for example, I want to add a javascript alert() when the save button of Account is clicked. Is this possible? If it is, can you share me some examples?

Your help will be greatly appreciated.

Thanks a lot,

apex code execute on server side and java script execute on client side.
so it's not possible to add javascript in apex code.


As was mentioned above, there is no way to do this with a server side trigger, it doesn't interact directly with the UI when executed anyway.  You should look into adding an scontrol on the page to perform your desired functions.

Check the online help for "Useful S-Controls"


Hey , as said before, the apex trigger cannot have js.
If you want to add a alert() message when the form is submited , you can do it with the onclick event of the apex:commandbutton tag.
Take a look at the different apex components attributes at :

That is true, the onclick would work, if he is replacing the standard page with a visualforce page.
If he is just trying to use a trigger on the standard object and use the standard page layout, it would not.
I see. Thanks for the quick reply. Too bad, the reason for this is because i need to refresh new account page after saving. Im using a future method to call for an external website, do some modifications in the account record, then reflect the changes in the page. But since it is a future method, i still need to refresh the page to be able to see the changes made. I was hoping i can put some javascript to refresh the page after the modifications.

Anyway, thanks a lot! Got to find a new way to do this. :)
How do u call a external web site through apex
Look in the documentation at the Apex Web Service Integration, specifically the HTTP (RESTful) services Classes.  Note that you need to add the external site to you list of authorized remote sites in your setup.