Enabling Email Templates in the Winter '12 Force.com IDE

Update: Thanks to Jon Wu for noticing that the original code wouldn’t compile - wordpress removed the tags for me in a “helpful” way. I have updated the code below to fix this, you can also get it from his gist (which is where I should have put it - will do next time!)

I would like to start this with a big thanks to Andy Mahood, Gary Breavington and Michael Botos for their guidance on this matter which I have expanded upon.

With the release of the Winter ‘12 Force.com IDE update, there have been a few teething issues which have caused a number of problems. ONe of these is that it seems when connected to an org you cannot bring down the email templates folder as part of the metadata by default. I tweeted and posted to see if anyone else was having the same issues and thanks to Gary, Andy and Michael I was directed to the following github gist that give an outline of how to change the package file to include the templates.

So the problem with this method is that it can be very time consuming if you have a large number of folders with email templates you have created. Run the code snippet below in the execute anonymous window and it will output some nice XML text for you to copy across into the package.xml file. Easy!

String output = '\n<types>\n';
List<EmailTemplate> templates = [Select e.FolderId, e.DeveloperName From EmailTemplate e];
Map<Id, Folder> folders = new Map<Id, Folder>([Select f.Id, f.DeveloperName From Folder f where f.DeveloperName != null]);
Set<Id> folderIds = new Set<Id>();

for (EmailTemplate template: templates) {
  if (folders.keySet().contains(template.FolderId)) {
    if (folderIds.contains(template.FolderId)) {
      output += '\t<members>' + folders.get(template.FolderId).DeveloperName + '</members>\n';
    output += '\t<members>' + folders.get(template.FolderId).DeveloperName + '/' + template.DeveloperName + '</members>\n';

output += '</types>\n';
Share on Twitter, Facebook, Google+
Prev Next