[SalesForce] “Entity type: ‘Folder’ is unknown” when deploying with the Force.com Migration Tool

The Force.com Migration Tool throws the error Entity type: 'Folder' is unknown when attempting to deploy with the following build.xml file. As far as I know, one should be able to retrieve/deploy folders- "Folder" is listed as a type for the Metadata API in the Salesforce docs. I'm able to retrieve and deploy the other types in the file as expected. Why am I unable to deploy folders?

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>AnApp</members>
        <name>Folder</name>
    </types>
    <types>
        <members>AnApp</members>
        <name>CustomApplication</name>
    </types>
    <types>
        <members>AnApp_Project__c</members>
        <name>CustomObject</name>
    </types>
    <types>
        <members>AnApp_Project__c</members>
        <name>CustomTab</name>
    </types>
    <types>
        <members>AnApp/AnApp_logo.png</members>
        <name>Document</name>
    </types>
    <version>37.0</version>
</Package>

Best Answer

"Folder" is only a base type for the four types of folders in Salesforce. If we were talking in programming lingo, it's an "abstract" type. You'll want to read the Folder entry for full details, but basically you actually retrieve them as one of DocumentFolder, DashboardFolder, EmailFolder, or ReportFolder. These folders exist in the corresponding document, dashboard, email, or report folder.

For example, a DocumentFolder called CompanyDocuments would be found in the documents folder, called CompanyDocuments-meta.xml:

<?xml version="1.0" encoding="UTF-8"?>
<DocumentFolder xmlns="http://soap.sforce.com/2006/04/metadata">
    <accessType>Public</accessType>
    <name>CompanyDocuments</name>
    <publicFolderAccess>ReadOnly</publicFolderAccess>
</DocumentFolder>

And in the package.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>CompanyDocuments</members>
        <name>Document</name>
    </types>
    <version>36.0</version>
</Package>

Notice how it's listed under the base type (e.g. Document), but doesn't have the usual Document syntax (e.g. CompanyDocuments/Document1.doc).

Your file would be modified as follows:

<types>
    <members>AnApp</members>
    <members>AnApp/AnApp_logo.png</members>
    <name>Document</name>
</types>