11

Is it possible to retrieve email templates using sfdx?

I would assume that I could get them using sfdx force:source:retrieve -m EmailTemplate:Folder/TemplateName but everything I try results in

=== Retrieved Source
No results found

EDIT: Solved with AngelSalazars answer.

In case anyone finds it useful, my solution to get all email templates from an org is

emails="`sfdx force:data:soql:query -q "select Id, Name, DeveloperName, NamespacePrefix, Folder.DeveloperName, Folder.NamespacePrefix, FolderId from EmailTemplate" -r json | jq -r '.result.records[] | "EmailTemplate:" + if (.Folder) then if (.Folder.NamespacePrefix) then .Folder.NamespacePrefix + "__" else "" end + .Folder.DeveloperName else "unfiled$public" end + "/" + if (.NamespacePrefix) then .NamespacePrefix + "__" else "" end + .DeveloperName + ","' | tr -d '\n'`"
sfdx force:source:retrieve -m "${emails%%,}"
6
  • are you trying to retrieve personal folder? Apr 8, 2019 at 11:46
  • Did you try using the template unique name? Apr 8, 2019 at 11:47
  • It should be like this - sfdx force:source:retrieve -m EmailTemplate:YOUR_EMAIL_TEMPLATE_UNIQUE_NAME Apr 8, 2019 at 11:47
  • I am trying to retrieve from a public folder. I dit try using only the template name but that doesn't work. I expected it should be Folder/DeveloperName because that is how you have to put them in a package.xml
    – H Alves
    Apr 8, 2019 at 12:54
  • did you find a solution? Apr 8, 2019 at 19:55

4 Answers 4

15

Apparently, you have to escape the $ and / characters

sfdx force:source:retrieve -m EmailTemplate:unfiled\$public\/YOUR_TEMPLATE_API_NAME -u YOUR_ORG
2
  • 1
    Thanks. Another problem for me was that I had to add a namespace prefix to the folder.
    – H Alves
    Apr 9, 2019 at 8:46
  • To add more clarity - the 'unfiled\$public\' is the folder name with the $ escaped (as AngelSalazar mentioned). So if you have a folder with the name foo and an email template with the api name of 'foo_test' you would retrieve with: sfdx force:source:retrieve -m EmailTemplate:foo\/foo_test -u YOUR_ORG_ALIAS Nov 21, 2022 at 18:13
6

After trying just about every combination I can think of / find on the internet, this worked for me:

sfdx force:source:retrieve -m EmailTemplate:'unfiled$public'/EMAIL_TEMPLATE_API_NAME

The kicker is the single quotes around unfiled$public. Hope this helps and please upvote me if this works for anyone!

1
  • As of 2023 the other answers did not work for me but this one did. Thank you. Mar 23, 2023 at 3:57
1

So I think there's an easier way to this if put the -m arguments in double-quotes you should have to use the escape character.

sfdx force:source:retrieve -m "EmailTemplate:unfiled public/YOUR_TEMPLATE_API_NAME" -u YOUR_ORG

1

If you have a folder named : My Folder than it will be

sfdx force:source:retrieve -u userAlias -m "EmailTemplate:My_Folder\/Email_Template_Name"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .