You need to sign in to do that
Don't have an account?
Matt Robertson
Messaging.SingleEmailMessage() not showing body
In my apex controller I call a SendEmail() method and it send an email correctly when called from one of my other methods but when I call it from another method in the same controller the body is empty. I have debuged the passed parameters and they are all the exact same as the method that works but it just sends an email with the correct subject with the body empty. The ResendEmail method is the one not working.
public void SendEmail(ID et) { Messaging.SingleEmailMessage mail =new Messaging.SingleEmailMessage(); Contact recipient = (Contact) currentrecord.getSObject('Contact'); system.debug(et); system.debug(recipient.id); mail.saveAsActivity = true; mail.setTargetObjectId(recipient.Id); mail.setTemplateId(et); mail.setWhatId(currentRecord.id); system.debug(currentRecord.id); Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail}); } public PageReference ResendEmail() { system.debug(resendtype); String resendtype2 =resendtype.remove('RMA').trim(); String templateID=''; templateID= RMA__c.getInstance(resendtype2).Email_Template_ID__c; System.debug(templateID); Contact recipient = (Contact) currentrecord.getSObject('Contact'); If(recipient.email == null || SkipEmail =='false') { system.debug('Email Will not be sent Recipient:' +recipient +' SendEmail:' +SkipEmail); } Else { system.debug('Email Will be Sent'); sendemail(templateid); } List <Task> updates =new List <Task> (); for (Task email: [SELECT ID,Status,RecordTypeID,CreatedDate,Subject FROM Task Where WhatID = :currentrecord.ID Order by CreatedDate DESC limit 1]) { email.recordtypeID ='012Q00000004wNk'; email.Type = resendtype; updates.add(email); update updates; } try { PageReference parentPage= new PageReference('/apex/RMA?scontrolCaching=1&id=' + currentRecord.Id); parentPage.setRedirect(true); return parentPage; } Catch(Exception ex) { ApexPages.Message msg =new ApexPages.Message(ApexPages.Severity.Error, ex.getMessage()); ApexPages.addMessage(msg); } return null; }
You can certainly add a try-catch to the messaging method in order to catch any issues (although since the email is firing, I'd be surprised if errors are encountered).
I would suggest adding try-catch in the sendemail method (and system.debug in the catch statement at least to see if any errors are thrown).
It seems to be a problem when using the actionfunction (the email that works does not use actionfunction because I dont need to pass any paramters) but all the parameters are passed correctly.