0

Java Script -

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}

 Var r =  Confirm("Are you sure, you want to send email");
 if (r==true)
{
    sforce.apex.execute("ContactsendEmail","sendEmail",{Email:"{!Contact.Email}"});
    alert("Contact Email " + {!Contact.Email});
    alert("Email Sent Successfully");
}

Class -

global  class ContactsendEmail {

webservice static void sendEmail(String Email)
    {
     Messaging.Singleemailmessage mail = new Messaging.Singleemailmessage();
    mail.setToAddresses(new String[] {'surinder.b.singh@accenture.com'});
    mail.setReplyTo('noreply@privatebudget.com');
    mail.setSenderDisplayName('Private Budget App');
    mail.setSubject('Private Budget records for ' + Date.today().month() + ' ' + Date.today().year());
    mail.setBccSender(false);
    mail.setUseSignature(false);
    mail.setPlainTextBody('This is a test');
    system.debug('@@@@ sendEmail - mail : ' + mail);
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

Javascript code fires on a custom button on contact. I ma getting error like - "A problem with Javascript on this button - Unexpected identifier"

  • try to remove alert and then try. – Tushar Sharma Sep 8 '17 at 10:41
  • Hi Tusar, Still getting same error. Unexpected identifier. – surinder rana Sep 8 '17 at 10:42
  • JavaScript is case sensitive so you need e.g. var r = confirm(.... – Keith C Sep 8 '17 at 10:44
  • 1
    Well I guess unrelated but, with lightning does it still makes sense to use connection.js and that too api version 15.0 ? – Avidev9 Sep 8 '17 at 11:11
1

Here you need to change

var r =  confirm("Are you sure, you want to send email");   

Notice the var and confirm as Javascript is case sensitive. Complete code for reference.

{!REQUIRESCRIPT("/soap/ajax/40.0/connection.js")}
    {!REQUIRESCRIPT("/soap/ajax/40.0/apex.js")}

     var r =  confirm("Are you sure, you want to send email");
     if (r==true)
    {
        sforce.apex.execute("ContactsendEmail","sendEmail",{Email:"{!Contact.Email}"});

        alert("Email Sent Successfully");
    }
  • Thanks for the help. Yes it was case sensitive thing issue – surinder rana Sep 8 '17 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.