進行状況の追跡を始めよう
Trailhead のホーム
Trailhead のホーム

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, create a new project by running the following command. This creates our new project named: PackageXMLProject
    sfdx force:project:create -n PackageXMLProject
  2. 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
3. Select Documents and then select PackageXMLProject folder.
4. Click the new file icon New File.
5. Name the new file package.xml.
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: Sticker__c
  • 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>46.0</version>
</Package>

7. 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:
    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.

    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. 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

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 -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:

Response in terminal window when a scratch org being created is completed.

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