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
devNut!devNut! 

SendEmail -SingleEmailMessage -> INVALID_FIELD_WHEN_USING_TEMPLATE


Why can't the plain text body and html body be specified when sending a SingleEmailMessage using a template through the API ?

The Salesforce UI allows a user to select a template and edit the email body before sending.


---------------------------------------------------
<sendEmailResponse xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <result>
    <errors>
      <fields xsi:nil="true"/>
      <message>
        When a template is specified the plain text body, html body and subject may not be specified
      </message>
      <statusCode>
        INVALID_FIELD_WHEN_USING_TEMPLATE
      </statusCode>
      <targetObjectId xsi:nil="true"/>
    </errors>
    <success>
      false
    </success>
  </result>
</sendEmailResponse>
werewolfwerewolf
I understand your point, but you can't possibly both use a template and make edits to the body in a single call.  I don't think you can do this right now via the API anyway but it would have to be 2 calls, one to resolve the template to a body and the second to actually send the email with that body.
devNut!devNut!
Exactly.

I was hoping it would work that way.
vanessenvanessen

Another problem that may cause this error is that for singlemail you are sending more than 10 mails in 1 go.