Created
December 7, 2011 23:30
-
-
Save wuservices/1445287 to your computer and use it in GitHub Desktop.
Generating package.xml snippet to get email templates to Force.com IDE Winter '12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
Without the check, you'll throw a NullPointerException when getting the DeveloperName on line 15
ahh...makes sense..thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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