Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generating package.xml snippet to get email templates to IDE Winter '12
// Derived from
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';
Copy link

anupj commented Dec 22, 2011

Hi Paul,

Nice one! Thanks for the code!
A quick observation - I'm not sure why you need the if statement on line 10, the 'if' statement on line 11 should suffice.

I haven't tested this, but the output should be the same if you remove the if statement from line 10.


Copy link

Without the check, you'll throw a NullPointerException when getting the DeveloperName on line 15

Copy link

anupj commented Dec 22, 2011

ahh...makes sense..thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment