Build a Package.xml Manifest
After completing this unit, you’ll be able to:
- Build a package.xml file.
- Pull specific metadata from your org using package.xml.
To keep the unmanaged package and the project organized, it’s a good idea to create a workspace (or simply a directory folder) to store the metadata you are working with. Let’s create a new project to catch the metadata on your machine.
- In the terminal window in VS Code, create a new project by running the following command. This creates our new project named: PackageXMLProject
sfdx force:project:create -n PackageXMLProject
- Navigate to the new project folder by copying and pasting the following command, then pressing Enter.
This step builds a collection of folders and files that make it easier for you to use the Salesforce CLI to manage metadata and packages.
The time has come for the first big step in our adventure. We’ve talked a lot about package.xml files, and now it’s time to build one yourself. As you write this file, keep in mind the names of the metadata components identified in this XML. Each component declared in package.xml will be pulled into the project you just created when you retrieve metadata from your playground. Be sure that you have all the components you want to grab properly listed and named in the package.xml file.
1. In the VS Code app, click File > Open
3. Select Documents and then select PackageXMLProject folder.
4. Click the new file icon
5. Name the new file
6. Next, identify the metadata to be pulled by copying and pasting the following XML into package.xml.
- Custom Object: Enter in the API name:
- Custom Tab: Enter in the API name for the Sticker object:
<?xml version="1.0" encoding="UTF-8"?> <Package xmlns="http://soap.sforce.com/2006/04/metadata"> <types> <members>CUSTOM OBJECT API NAME HERE</members> <name>CustomObject</name> </types> <types> <members>CUSTOM TAB API NAME HERE</members> <name>CustomTab</name> </types> <version>46.0</version> </Package>
7. Click File > Save.
Once the XML file is ready, it should look something like this:
The next step is to pull the existing metadata out of the org and into the project by using the package.xml file created in the previous step and a Salesforce CLI command.
- In the terminal window in VS Code, run the following command to retrieve the metadata identified in the package.xml file:
sfdx force:source:retrieve -u DevHub -x ./package.xml
This command retrieves the metadata referenced in the XML file (-x) from the org, and adds the metadata files to the force-app folder.
Once the command is finished running, it’s a good idea to visually confirm the assets identified in the package.xml are in their correct folders. In the VS Code folder tree, confirm that the
Sticker__cobject and tab are in the the force-app/main/default folder.
For example, the package.xml file specifies that we grabbed only a custom object named Sticker__c. When you click into the force-app/main/default/objects folder, you should see a folder named
Sticker__c, containing a file named
Now that you’ve pulled the metadata from your playground into your project, the next step is to create a scratch org and use it to create more components for the application.
Next, create the scratch org that you’ll use to make changes to the metadata files and build more components for the sticker app.
- In the terminal window in VS Code, run the following command to create a scratch org. You should also set this scratch org as your default, so be sure to use the -s flag.
sfdx force:org:create -f config/project-scratch-def.json -s
Typically, the command completes in less than a minute. The results will look like this:
You get two items in the output: the org ID and the username. Be sure to copy those down for later.
Now that you have a safe place to do some development, let’s create some components and add them to the sticker project.