Search code examples
salesforceforce.com

Force.com Migration Tool : Email Templates


I am looking to retrieve all email templates using Force.com ant migration tool. I believe we can not have bulk retrieve for Email Templates, Reports etc.

Is there any way we can retrieve all email templates in one go without specifying each template name? I believe we can some custom implementation using Metadata API, but wondering if someone has already implemented custom ant task for it.

Thanks in advance.


Solution

  • Email Templates, Reports etc. are in folders, so you must provide the containingFolder attribute to the sf:bulkRetrieve task and you'll get back all the items in that folder. For example:

    <sf:bulkRetrieve 
        username="${sf.username}" 
        password="${sf.password}" 
        serverurl="${sf.serverurl}" 
        retrieveTarget="retrieveUnpackaged" 
        metadataType="EmailTemplate"
        containingFolder="SalesTemplates"
    />
    

    To find the folder names themselves, you can query the Folder object and filter on the Type column for the metadata type you are interested in. For example:

    SELECT DeveloperName FROM Folder WHERE Type = 'Email'