• Renato Solu
  • NEWBIE
  • -1 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
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?
I'm having an issue where Salesforce raises me an exception while trying to send three email messages (using the SingleEmailMessage class).

The exception code is INVALID_FIELD_WHEN_USING_TEMPLATE and it says When a template is specified, the plain text body, html body, subject, charset, and "treatBodiesAsTemplate" may not be specified. It would be a pretty straightforward thing to solve, however I am not setting any of those fields in my code.

In my code, I basically get a Contact Id, an Opportunity Id, and the Opportunity Owner's email address to send the email to. I am setting the email as BCC. Do notice though that I have created similar code to other classes in the organization, and they work just fine (setting a single email message with a template and bcc field).

If it is of any help, I also posted the question to Salesforce StackExchange.
I have an object layout displayed as a tab inside Sales Console. I have some Javascript attached to the onClick event of a button on the layout. In the Javascript I would like to retrieve the Base URL displayed in the browser. So if I have 'https://[instancenumber].salesforce.com/console' I would like to get 'https://[instancenumber].salesforce.com'. I use within Javascript:

console.log({!$Site.BaseUrl});

but I always get NaN. I know that I might use Javascript directly but I would like to know why this Salesforce approach does not work and I can make it work. Thanks
I'm having an issue where Salesforce raises me an exception while trying to send three email messages (using the SingleEmailMessage class).

The exception code is INVALID_FIELD_WHEN_USING_TEMPLATE and it says When a template is specified, the plain text body, html body, subject, charset, and "treatBodiesAsTemplate" may not be specified. It would be a pretty straightforward thing to solve, however I am not setting any of those fields in my code.

In my code, I basically get a Contact Id, an Opportunity Id, and the Opportunity Owner's email address to send the email to. I am setting the email as BCC. Do notice though that I have created similar code to other classes in the organization, and they work just fine (setting a single email message with a template and bcc field).

If it is of any help, I also posted the question to Salesforce StackExchange.