You need to sign in to do that
Don't have an account?
Trigger to Send Visual Force Email Template UNKNOWN_EXCEPTION Parameter value is null
I have a trigger that sends an email using a Visual Force Email template to a contact when an Opportunity stage changes to a couple specific values and the type of transaction (custom field) is set to a couple of specific values. There is a text field on the opportunity that holds an email address that this email is to be sent to. A query using this text field determines if a contact exists with this email or if it does not exists, creates a dummy contact. The existing contact or dummy contact is the recipient. A "Send Test and Verify Merge Fields" on the template works fine. The Trigger won't deploy and here is the debug code.
mail=Messaging.SingleEmailMessage[
getBccAddresses=null;
getCcAddresses=null;
getCharset=null;
getDocumentAttachments=null;
getFileAttachments=null;
getHtmlBody=null;
getPlainTextBody=null;
getTargetObjectId=0037000000lx8iHAAQ;
getTemplateId=00X700000016C9gEAE;
getToAddresses=null;
getWhatId=0067000000IkfgVAAR;
isUserMail=false;]
21:11:27.566|METHOD_ENTRY|[77,4]|Messaging.sendEmail(LIST:Messaging.SingleEmailMessage)
21:11:27.749|EXCEPTION_THROWN|[77,4]|System.EmailException: SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, java.lang.NullPointerException: Argument Error: Parameter value is null
21:11:27.751|METHOD_EXIT|[77,4]|sendEmail(LIST:Messaging.Email)
21:11:27.751|FATAL_ERROR|System.EmailException: SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, java.lang.NullPointerException: Argument Error: Parameter value is null
How can I determine what parameter value is null?
Thanks
As the debug log states the problem lies in the fact that many of the parameter required for send email are null:-
mail=Messaging.SingleEmailMessage[
getBccAddresses=null;
getCcAddresses=null;
getCharset=null;
getDocumentAttachments=null;
getFileAttachments=null;
getHtmlBody=null;
getPlainTextBody=null;
getTargetObjectId=0037000000lx8iHAAQ;
getTemplateId=00X700000016C9gEAE;
getToAddresses=null;
getWhatId=0067000000IkfgVAAR;
isUserMail=false;]
This is causing inability to deploy your code. Can you share the test methods which you have written for this as cause of the error lies there.
Also please try hardcoding the values and see if your code gets deployed.
Why dont you remove the fields that have null, as they are optional and give a try again?
Regards,
Imran
Thanks for both your replys. This is a Visual Force Email Template, therefore, all the addresses are not optional but can not be populated. The targetObjectId is populated and is required. The remaining fields are not required as it is a VF Email template. So, I believe all the red fields are not required and in some cases can't be populated. I only populate the targetObjectId, templateId, whatId and SaveAsActivity(false) as depicted below.
mail.setSaveAsActivity(false);
mail.setTargetObjectId(c.id);
mail.setWhatId(trigger.new[i].id);
mail.setTemplateId(tempId);
getBccAddresses=null;
getCcAddresses=null;
getCharset=null;
getDocumentAttachments=null;
getFileAttachments=null;
getHtmlBody=null;
getPlainTextBody=null;
getToAddresses=null;
Hi Brian,
Were you able to resolve the issue or still you are stuck with that?
I have not made any changes, so, I don't have a resolution of why there is a null parameter in the send email.
Hey Guys,
Its caused by the apex:image tag, i have no idea why but when an email is fired from workflow or and @future which renders as a pdf with an image all hell breaks loose....
Im still trying to find a solution but getting nowhere quickly,
Did you ever find a solution? I'm trying to send emails from an Apex batch job. I'm using a Visualforce email template which uses an image tag. I get the same error as shown in the earlier posting. If I take the image tag out of the template, it runs fine.
Sadly no solution or workaround.
Also no response from saleforce to say if it is a feature, undocumented feature or an issue :/