I'm having trouble deploying my mdapi


  1. sfdx force:mdapi:retrieve -s -r ./mdapipkg -p -- This gets the latest version of managed package from our Packaging Org -- I did not convert to the new source format
  2. In VSCode, I'm now trying to push it to my new PDO and that's where the problems lie. I've tried a handful of commands.

What does "Unexpected file found in package directory" mean here? I even commented out Dashboards type on my package.xml and still got this error:

Unexpected file... /dashboards/____-meta.xml

**____-MacBook-Pro-2:salesforce-app me$ sfdx force:mdapi:convert --rootdir force-app/main/default --outputdir tmp_convert**
ERROR running force:mdapi:convert:  Unexpected file found in package directory: /Users/me/Dev/____/salesforce-app/force-app/main/default/dashboards/____-meta.xml
**____-MacBook-Pro-2:salesforce-app me$ sfdx force:source:deploy -p force-app/main/default**
ERROR running force:source:deploy:  Unexpected file found in package directory: /Users/me/Dev/_____/salesforce-app/force-app/main/default/dashboards/Reportname-meta.xml
**____-MacBook-Pro-2:salesforce-app me$ sfdx force:mdapi:deploy -d force-app/main/default**
Job ID | 0Af5w00000XORXICA5
MDAPI PROGRESS | ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ | 0/100 Components
The deploy request did not complete within the specified wait time [0 minutes].
To check the status of this deployment, run "sfdx force:mdapi:deploy:report"
**____-MacBook-Pro-2:salesforce-app me$ sfdx force:mdapi:deploy:report**
Job ID | 0Af5w00000XORXICA5
MDAPI PROGRESS | ████████████████████████████████████████ | 0/0 Components

=== Component Failures [1]
TYPE   FILE                 NAME         PROBLEM
─────  ───────────────────  ───────────  ───────────────────────────────────────────────────────────────────────────────────────
Error  default/package.xml  package.xml  The specified package namespace: ____ does not match the namespace for the server:

ERROR running force:mdapi:deploy:report:  The metadata deploy operation failed.

2 Answers 2


There seems to be a couple of different problems here. First, we need to be clear about which commands are being used to deploy which type of metadata.

Salesforce DX-format source is deployed by sfdx force:source:deploy

Metadata API-format source is deployed by sfdx force:mdapi_deploy.

If converting MDAPI to SFDX format does not succeed, it is unlikely that the resulting force-app directory will be cleanly deployable. Without more information, perhaps in a separate question, I don't see a clear reason why your source conversion failed.

If you're deploying Metadata API-format source, the content of your package.xml should match your src directory, and you shouldn't have any spurious files in src.

The last snippet you shared seems to be the most directly understandable problem:

Error default/package.xml package.xml The specified package namespace: ____ does not match the namespace for the server:

ERROR running force:mdapi:deploy:report: The metadata deploy operation failed.

Your package.xml appears to contain namespaced elements of some kind, while you're deploying to a Developer Edition org that either does not have a namespace (most likely) or has a different namespace.

If your package source contains explicit references to your namespace, you need to build it in a namespaced scratch org, which you can enable by linking your namespace to your Dev Hub.

It's definitely preferable to keep all explicit namespace references out of your metadata because it makes it possible for you to deploy it cleanly to un-namespaced orgs (which should be scratch orgs, not Developer Editions!) during your development process.

More broadly, you should get yourself into a position where you are never retrieving from packaging. Your source repo should be the source of truth for this package. New customizations get deployed to packaging; there should never be changes to retrieve from packaging, and your Git master should always be in a state to deploy cleanly.

  • Thanks so much David. There's a lot here to process. I am new to sfdx. I understand the difference between source and mdapi. I guess because of the kind of retrieve I did, I should also be focused on mdapi for deploy. I have questions around source vs mdapi. Can I retrieve a package with either format? Which format is best to store in Github? How can I identify the two formats when assessing an existing Repo? (I promise I have read the official docs on this, and I'm afraid they don't answer these directly. Feel free to link to the right doc) May 12, 2020 at 22:35
  • I verified, the code does not have hard-coded namespace anywhere. Also, I commented out <namespacePrefix> in my package.xml, now I get this error: Ryans-MacBook-Pro-2:salesforce-app me$ sfdx force:mdapi:deploy:report Job ID | 0Af5w00000XOU1jCAH MDAPI PROGRESS | ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ | 0/17 Components ERROR running force:mdapi:deploy:report: The metadata deploy operation failed. May 12, 2020 at 22:40
  • Also, could you say what is going on when I see this "Unexpected file found in package directory: " May 12, 2020 at 23:05
  • More broadly, my client has a Managed Package in a Packaging Org, and it was built by folks who are no longer around. It's available on AppExchange. My client also has a Github Repo. When I compare what's in the Managed Package to what's in the Repo... A) There are over 100 files in the package that are not in the Repo. If the package is what customers are happily using, I should take it as the source of truth over the Repo. But now I've merged the files into the Repo. Now, for new dev, I should use Scratch orgs... could you provide the best doc to follow to do that? May 12, 2020 at 23:11
  • OK, there's a lot to unpack here and it's definitely too much for a comment thread, so briefly: (1) onboarding a package from non-scratch-org development into scratch orgs is hard; I have personally done it ~15 times and every package breaks in different ways. (2) You can use either Metadata API or Salesforce DX format. If you're going to use Salesforce DX development, use SFDX format. (3) "Unexpected..." means pretty much what it says, but figuring out what file it refers to is trickier.
    – David Reed
    May 12, 2020 at 23:24

I changed my entire process for retrieve from Packaging Org and now I have no conflicts on deploy to Dev Org.

  1. auth into packaging org

  2. sfdx force:mdapi:retrieve -s -r ./mdapipkg -p PackageName 
- unzip only to get the package.xml

    • refer to this package.xml in Step 3
  3. sfdx force:source:retrieve -x /Users/me/Dev/____/salesforce-app/mdapipkg/unpackaged/package.xml

  4. auth into dev org

  5. sfdx force:source:deploy -p force-app/main/default

Thanks @David Reed, I'll go through your answers again to see what more I can gleen. I'll have to start moving toward scratch org and treating Github as my source of truth.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .