I have some 100 odd HTML email templates. I need to edit all templates to replace once string with another. (It's a HTML snippet replacement).

Is there some Salesforce API with which I can accomplish this ?
Otherwise I would've to manually download each template and replace the string and re-upload.


You can work with email templates as with regular records.

EmailTemplate et = [SELECT Id, Body from EmailTemplate WHERE id='00X1i000000ljmvEAA'];
et.Body.replace('asdf', '1234');
update et;

Just write your script and execute it in anonymous console.

  • Oh, I didn't realize there is something like this - Can you give me some reference to where I can find more info on this ? Where do I run this ? Which console ? Salesforce console ? Or do I need to write JavaScript code to run in nodeJS on my laptop ?
    – anjanesh
    Jul 21 at 9:29
  • help.salesforce.com/…
    – Damecek
    Jul 21 at 9:31
  • Got it, thanks.
    – anjanesh
    Jul 21 at 9:32
  • Does Body.replace work for HTML templates ? salesforce.stackexchange.com/q/154376/99464
    – anjanesh
    Jul 21 at 12:38
  • you can try et.HtmlValue
    – Damecek
    Jul 21 at 12:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.