function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Renato SoluRenato Solu 

Button works in sandbox, but not in production.

I have created a custom button to send an email to a contact in an Opportunity. In sandbox, this works fine. But when I deployed it to production, it stopped working, and SF is throwing me an INVALID_FIELD_WHEN_USING_TEMPLATE error.

System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_FIELD_WHEN_USING_TEMPLATE, When a template is specified, the plain text body, html body, subject, charset, and "treatBodiesAsTemplate" may not be specified : [].

However, I do not set any of those in my code. The things I set in my SingleEmailMessage instance are:
  • setSaveAsActivity(false);
  • setWhatId(Id);
  • setTargetObjectId(Id);
  • setOrgWideEmailAddressId(String);
  • setBccAddresses(String[]);
  • setTemplateId(Id)
And this works in sandbox, but not in production. It is the same code! What can it be?