What does "version" do in package.xml in Salesforce?

If you have worked with package.xml in Salesforce to retrieve or deploy components, you have seen the "<version></version>" tag. Do you know what exactly it does?

Version determines which version of the Metadata API Salesforce will use to retrieve or deploy your components. And that will mean that only those properties will be retrieved or deployed that were available in that version.

Here is a package.xml file that I used to retrieve the same component (one custom object and one custom profile) with different versions. The org that I used is currently on the Winter '22 release of Salesforce (i.e., version 53.0).

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Animal__c</members>
        <name>CustomObject</name>
    </types>
    <types>
        <members>AA System Administrator</members>
        <name>Profile</name>
    </types>
    <version>XX.0</version>
</Package>

I retrieved the metadata using the above package.xml with versions 10.0 and 20.0. And here is the difference between the XMLs produced by these versions. As you can see, new object-specific permissions were available in version 20.0, which were not available in version 10.0.

And here is the difference between the XMLs produced by versions 40.0 and 53.0. It looks like not a lot changed between these two versions in the profile (this, of course, is in relation to the metadata that were retrieved along with the profile).

This also means that you should be able to retrieve the metadata extracted with one version and deploy it using another version, as long as all the metadata properties are supported in both versions.

If not, then trying to deploy metadata with a version that is different from what was used to retrieve it will throw an error like this. In this example, I was trying to deploy the custom object and custom profile using version 53.0, which was retrieved using version 20.0.

But deploying it using version 20.0 worked just fine.