Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generating package.xml snippet to get email templates to Force.com IDE Winter '12
// Derived from http://paulbattisson.com/?p=80
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>();
folderIds.addAll(folders.keySet());
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';
folderIds.remove(template.FolderId);
}
output += '\t<members>' + folders.get(template.FolderId).DeveloperName + '/' + template.DeveloperName + '</members>\n';
}
}
output += '</types>\n';
System.debug(output);
@anupj

This comment has been minimized.

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.

Regards,
Anup

@wuservices

This comment has been minimized.

Copy link
Owner Author

wuservices commented Dec 22, 2011

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

@anupj

This comment has been minimized.

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
You can’t perform that action at this time.