You need to sign in to do that
Don't have an account?
Outbound Email functionality
Hi,
I am trying to create a Email Functionality on click a custom button. i.e. I have a button that runs javascript on click and it executes the Apex class.
Button is:
-------------------
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
var result=sforce.apex.execute( "EmailMe", "EmailFunction", {});
alert(result);
-------------------
Apex Class is:
--------------------
public with sharing class EmailMe {
private String[] toAddresses;
public EmailMe(){
List<User> currentUser = [Select Email from User where Id =:UserInfo.getUserId()];
String[] toAddresses = new String[] {currentUser[0].Email};
}
public String EmailFunction(){
Messaging.reserveSingleEmailCapacity(4);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(toAddresses);
mail.setSubject('Test Mail');
mail.setPlainTextBody('Your Case has been created for testing');
Messaging.SendEmailResult[] res = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
if(res[0].isSuccess()){
return 'Email is sent';
}
else{
return res[0].getErrors()[0].getMessage();
}
}
}
--------------------
But i am recieving something like this error:
"{http:// soap.sforce.com/schemas/package/EmailMe}Emailfunction please check the WSDL for the service.."
Do you think I have to setup some connection or something??
I am using my DEV org.
Help!!
Hi Prats,
your apex class/method must be setup as a web service. Have a look at this URL:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_and_ajax.htm
I hope it helps!
Cheers!
Martin
All Answers
Hi Prats,
your apex class/method must be setup as a web service. Have a look at this URL:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_and_ajax.htm
I hope it helps!
Cheers!
Martin
Hey thanks!
But now, even though i am receiving alert as "Email is sent".. I am not receiving any actual mail in mailbox!!
Do you reckon why??
Hi,
I'm not sure. But I would add some System.debug() statements to the class to track what's going on.
Cheers!
Martin
There is not much that i could do with System.debug()
Hence I created a "debug log" for myself.. and this is the result after i clicked the button and got "Email is sent" message.
Request Type Application Operation Status Duration (ms) Log Size (bytes) Start Time
Api Unknown APEXSOAP Success 159 6,691 04/21 14:53:07
Still no email in mailbox :( .. I guess there is no problem from SF side to send email.. Pls suggest!!
Hey, I recieved the Email. Though not on my office id, but my personal mail, the problem must be because of Firewalls etc.!! YippY!!
You might want to check the Email Administration settings and see if you have "email security compliance" turned on, otherwise your emails might appear spoof'd and be blocked by your corp email server.