You need to sign in to do that
Don't have an account?
Nidhi Sharma 17
Passing fields of Contact object as parameters into an Apex Class via Custom Button in a Task
I have an Apex Class to send an Email to someone as a Contact.
I want to send the 'Email' and the 'FirstName' fields of a particular Contact associated to a Task as parameters to the Apex Class when I click the Custom Button - 'Send' on the task detail page, so that I can send the email from the Apex Class using these field values.
My Apex Class :
My Custom Buttom in Task :
The problem here is the variables 'eid' and 'fname' remains undefined and is not passing into the Apex Class.
Need some help on this. Hope I made the question clear.
I want to send the 'Email' and the 'FirstName' fields of a particular Contact associated to a Task as parameters to the Apex Class when I click the Custom Button - 'Send' on the task detail page, so that I can send the email from the Apex Class using these field values.
My Apex Class :
global class TestMailClass { WebService static Integer TestMailMethod(String emailAddress, String fname1) { // Create a new Email Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {emailAddress}; mail.setToAddresses(toAddresses); // Set who the email is sent from mail.setReplyTo('myemail@abc.com'); mail.setSenderDisplayName('ABC'); // Set email contents - used variables! mail.setSubject('TEST EMAIL'); String body = 'Dear ' + fname1 + ', '; body += 'This is a sample mail that I am trying for the first time.'; body += 'I write to send a random email '; mail.setHtmlBody(body); Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail}); return 0; } }
My Custom Buttom in Task :
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")} var cntct = new sforce.SObject("Contact"); cntct.Id = "{!Contact.Id}"; var eid = new String(cntct.Email); var fname = new String(cntct.FirstName); var result = sforce.apex.execute("TestMailClass", "TestMailMethod",{emailAddress:eid, fname1:fname});
The problem here is the variables 'eid' and 'fname' remains undefined and is not passing into the Apex Class.
Need some help on this. Hope I made the question clear.
try below java script code
Regards,
Bhanu Mahesh
All Answers
try below java script code
Regards,
Bhanu Mahesh