Package.Xml For Fetching All Metadata From Salesforce Org

Hey there, today we’re diving into the use of Package.xml for retrieving all metadata from a Salesforce Org. This XML file specifies the components and associated metadata forming a Salesforce package. With the right metadata included in your package.xml, you can leverage the Salesforce Metadata API to fetch those components.

An effective method to fetch LWC components involves utilizing the package.xml file. This file, in XML format, outlines the components and additional metadata that constitute a Salesforce package.

Main Points:

  • Generate a fresh package.xml file at your project’s root directory.
  • Specify the types of metadata intended for retrieval/deployment within the package.xml.
  • Using the <members> element, define the desired metadata components for retrieval, and use the <name> element to designate the type of metadata.
  • The * wildcard is employed to collect all components and all metadata types.
  • Access Salesforce components through Salesforce CLI and Workbench for retrieval.
  • To retrieve all metadata from a Salesforce org, include the following elements in your package.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>*</members>
        <name>*</name>
    </types>
    <version>56.0</version>
</Package>

Code :

# Retrieve Tabs and Quick Actions :

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>SampleTab</members>
        <name>CustomTab</name>
    </types>
    <types>
        <members>ObjectName.SampleQuickAction</members>
        <name>QuickAction</name>
    </types>
    <version>56.0</version>
</Package>

# Retrieve LWC Component :

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

# Retrieve Lightning Aura Component :

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

# Retrieve Apex Class :

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

# Retrieve Apex Trigger :

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

# Retrieve Visualforce Page :

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

# Retrieve Visualforce Component :

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

# Retrieve Custom Label :

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

# Retrieve Custom Metadata :

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>CustomMetadataName.SampleRecord</members>
        <name>CustomMetadata</name>    
    </types>
    <version>57.0</version>
</Package>

# Retrieve Custom Object and fields :

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>SampleCustomObject</members>
        <name>CustomObject</name>    
    </types>
    <types>
        <members>ObjectName.CustomFieldName</members>
        <name>CustomField</name>
    </types>
    <version>57.0</version>
</Package>

# Retrieve Flow and Process Builder Process :

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>SampleProcessName</members>
        <members>SampleFlowName</members>
        <name>Flow</name>
    </types>
    <version>57.0</version>
</Package>

# Retrieve Email Template & Workflow :

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>FolderName/SampleEmailTemplateName</members>
        <name>EmailTemplate</name>
    </types>
    <types>
        <members>SampleWorkflow</members>
        <name>Workflow</name>
    </types>
    <version>57.0</version>
</Package>

# Retrieve Profile, Roles, Queues, Groups, Permission Set

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Sample Profile Name</members>
        <name>Profile</name>
    </types>
    <types>
        <members>SampleRoleName</members>
        <name>Role</name>
    </types>
    <types>
        <members>SampleQueueName</members>
        <name>Queue</name>
    </types>
    <types>
        <members>SamplePermissionSet</members>
        <name>PermissionSet</name>
    </types>
    <types>
        <members>SampleGroup</members>
        <name>Group</name>
    </types>
    <version>57.0</version>
</Package>