+ Start a Discussion
Jagannatha Reddy BandaruJagannatha Reddy Bandaru 

i want to send email from detailed page


i have created a button in detailed page that is send email , if i click that button how email will be forward from there,i think it is work out from java script but how??
please let me share your valuable suggestions .





Thanks,
Jagan
Pavan Kumar KajaPavan Kumar Kaja
U can call the apex method from js button. find the sample code below. and optionally u can pass the object parameters as shown in below.

write singleemailmessage in sendemail  method.


var account = sforce.sObject("Account");
var id = sforce.apex.execute("class","sendemail",
{lastName:"Smith",
a:account});
Jagannatha Reddy BandaruJagannatha Reddy Bandaru
Hi ashi,

i placed this code in button but i think we need to write the Apex class to perform the action on the button.

i tried to write a apex class but it is showing error message when i click a button

please tell me how it's possible(otherwise give me your mail id)



Thanks & Regards,
Jagan
Pavan Kumar KajaPavan Kumar Kaja
try using the below code


{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
sforce.apex.execute("OutboundEmails","SendEmailNotification", {id:"{!Account.Id}"});
window.alert("Account Id is sent." );



global class OutboundEmails {

WebService static void SendEmailNotification(string id) {

//create a mail object to send a single email.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

//set the email properties
mail.setToAddresses(new string[] {'pavanthetech@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 } );

}
}
My Email

Pavanthetech@gmail.com