Skip to main content
Free Agentforce workshops and AI Certifications: Learn more. Terms and conditions apply.

Build a Package.xml Manifest

Learning Objectives

After completing this unit, you'll be able to:

  • Build a package.xml file.
  • Pull specific metadata from your org using package.xml.

Create a New Project

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.

  1. In the terminal window in VS Code, navigate to the Documents directory (or wherever you want the project to be) with this command.
    cd Documents
  2. Create a new project by running the following command. This creates our new project named: PackageXMLProject.
    sf project generate -n PackageXMLProject
  3. Navigate to the new project folder by copying and pasting the following command, then pressing Enter.
    cd PackageXMLProject
    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.

Build a Package.xml Manifest

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
  2. Select Documents and then select PackageXMLProject.
  3. Open PACKAGEXMLPROJECT and click the new file icon New File.
  4. Name the new file package.xml.
  5. Next, identify the metadata to be pulled by copying and pasting the following XML into package.xml.
    1. Custom Object: Enter in the API name: Sticker__c
    2. Custom Tab: Enter in the API name for the Sticker object:
      Sticker__c
      <?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>58.0</version>
      </Package>
  1. Click File > Save.

Once the XML file is ready, it should look something like this:

Snapshot of a package.xml with metadata components.

Pull Metadata Package from Playground

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.

  1. In the terminal window in VS Code, run the following command to retrieve the metadata identified in the package.xml file:
    sf project retrieve start -o 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.
    List of metadata components that were pulled from the org.
    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.
  2. In the VS Code folder tree, confirm that the Sticker__c object 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 Sticker__c.object-meta.xml.
Note

If you don't see the custom object or tab in your project, confirm in your playground that you installed the unmanaged package from the previous unit, and that you specified the correct API names in package.xml.

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.

Create a Scratch Org

Next, create the scratch org that you'll use to make changes to the metadata files and build more components for the sticker app.

  1. 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 -d flag.
    sf org create scratch -f config/project-scratch-def.json -d

Typically, the command completes in less than a minute.

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.

Resources

在 Salesforce 帮助中分享 Trailhead 反馈

我们很想听听您使用 Trailhead 的经验——您现在可以随时从 Salesforce 帮助网站访问新的反馈表单。

了解更多 继续分享反馈