+ Start a Discussion

Where am I missing a semicolon?

I have a custom button which is supposed to send an email, but I'm getting the following error when I click it:

"A problem with the OnClick JavaScript for this button or link was encountered: missing ; before statement"

My button executes the following OnClick Javascript:


Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

I can't see a missing semicolon?
Someone please shed some light on this for me as I can't move forward until this is resolved.

Best Answer chosen by Admin (Salesforce Developers) 

Hi Lee,


As such we cannot use apex methods directly in AJAX.

We need to write a separate apex class and then it need to invoked in the AJAX using the below AJAX method,

sforce.apex.execute("ApexClassName", "webServiceMethod", {param1,param2..,paramn})


ApexClassName - should be the name of your class which sends mail.

webServiceMethod - is the method in that class

param1,param2..,paramn - are the parameters passed onto the method


Please refer to my blog post on Sending Email Alerts via AJAX, to get a detailed idea on procedure.

Let me know if you face any issues still.


I believe that my blog post solves your issue, mark this post as solved for the benefit of others.





Salesforce For All