I have a class which has a method to send an email with the record details attached to it. But for some reason I am not getting the email. Here is the VF and controller that I use(just the code in scope):

VF page I have:

<apex:commandButton action="{!sendEmail}" value="Send an email"/>

Extension I have:

public void sendEmail () {
OutboundEmails.SendEmailNotification(customobject.id); //customobject value I get it using getrecord() in extension's constructor.

The OutboundEmails looks like:

global class OutboundEmails {

WebService static void SendEmailNotification(string id) {
send and email // works fine because I test it by creating a custom button and calling this function from there.


What am I missing here?


Your code looks good, no red flags. The best way to troubleshoot is to use liberal system.debug statements, debug logs, and anonymous execution to find the failure point and fix it.

The mostly likely failure point is your passing a null to the sendEmailNotification method. So put add a System.debug('==>objectId: ' + customObject.Id); to your sendEmail method to confirm that customObject.Id is not null. Use the developer console to see the debug statements.

Once you know that the function is getting the id you can troubleshoot just the sendEmailNotification using the anonymous execution functionality in the developer console, e.g. OutboundEmails.sendEmailNotification(<yourid>);.

  • Hello , thanks for the answer. But I had a silly reason of not getting email. The email server I was using was down. I tested with gmail account and it worked!
    – SfdcBat
    Jun 2 '16 at 17:55
  • 1
    been there, the email logs in setup have been helpful for confirming delivery was attempted and ruling out salesforce as the trouble point Jun 2 '16 at 19:12

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.