The commands that Salesforce Extensions for VS Code and Agentforce Vibes IDE uses to deploy and retrieve your source assume that your files are in source format (rather than metadata format). Source format is optimized for working with version control systems. For details, see Salesforce DX Project Structure and Source Format in the Salesforce DX Developer Guide.
Because legacy tools such as Force.com IDE used the metadata format, you can’t directly open your such projects in VS Code. You must either convert your metadata to source format (using sfdx force:mdapi:convert) or create a new project and then retrieve the metadata from your org using the manifest (package.xml file) that you used in your previous IDE.
Convert Metadata to Source Format and Maintain Git History
If you have a Salesforce project that is in metadata format and tracked in Git, a bulk convert to the new source format loses all the revision history. Git has built in limits and it fails to detect the enormous number of changes that happen at the same time. The solution is to convert the project to source format in smaller chunks so that you can maintain the revision history. Let’s take the dreamhouse project as an example to follow the conversion steps.
Here’s a snapshot of the code structure in metadata format in the ./metadata folder.
To convert the project from metadata to source format without losing the git history, follow these steps:
Create a temporary SFDX project outside of the Git repo. This temporary project has the structure and a configuration file as required by a Salesforce project.
$ sf project:generate -n tempproj
Convert the project in metadata into a temporary project.
Now, you have two copies of the project, one in the original location and the other in the new directory temproj, where the project files after converting them to the source format are stored.
Move the sfdx-project.json file and the config folder. The sfdx-project.json file identifies the directory as a Salesforce project.
$ git commit -m "Converted triggers to source format"
Repeat these steps to convert all the files or folders that contain simple metadata format.
If the changes aren’t detected correctly, the metadata folder may have too many files. In such cases, setting a rename detection limit for merge allows all renames in a single commit. Use the merge.renameLimit variable to set this rename limit. This option doesn’t work for custom objects.
These commands set the rename detection limit and convert to source format in a single commit.
1`$ git config merge.renameLimit 999999`23`$ sfdx force:mdapi:convert -r src -d src2`45`$ rm -rf src`67`$ mv src2 src`89`$ git add -A`1011`$ git commit -m "Converted from metadata to source format"`1213`$ git config --unset merge.renameLimit # Return the git config option to the default`
Convert Metadata with Expanded Source
If the new format is of expanded source type where a single metadata item is split into multiple files (for example, Custom Objects), a good approach to convert:
Create the folder structure as required by a Salesforce project.