+ Start a Discussion
anil.ax822anil.ax822 

Triggering an Apex method with a Custom Button

Hi,

 

I have a custom button in account called 'submit' and it's a onclick Java script event when i click on the button it displays error

 

 

A problem with the OnClick JavaScript for this button or link was encountered:
{faultcode:'soapenv:Client', faultstring:'No operation available for request {http://soap.sforce.com/schemas/package/OutboundEmails}SendEmailNotification, please check the WSDL for the service.', }

 

 

iam using 21.0 version

JS code:

{!REQUIRESCRIPT("/soap/ajax/

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

var AccId= '{!Account.Id}';
sforce.apex.execute("OutboundEmails","SendEmailNotification", {id:AccId});
window.alert("Account Id is sent." )

Apex code:

global class OutboundEmails {
WebService static void SendEmailNotification(Id id) {

//create a mail object to send a single email.
Messaging.SingleEmailMessage mail = new
Messaging.SingleEmailMessage();
//set the email properties
mail.setToAddresses(new string[] {'Myself@gmail.com'});

mail.setSenderDisplayName('SF.com Email Agent');
mail.setSubject('A new reminder');
mail.setHtmlBody('an object with ID='+ id + ' is just clicked on.');
//send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );

}
}



ERROR:sforce is not defined



Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

I tried the same code in my org and its working for me.

Check the Version of your class also.

All Answers

Rahul SharmaRahul Sharma

I tried the same code in my org and its working for me.

Check the Version of your class also.

This was selected as the best answer
anil.ax822anil.ax822

Yeh it works fine for me

 

Thanks Rahul