Deploying Salesforce List Views

Define the List View in package.xml

The package.xml manifest file tells the Metadata API which components you want to retrieve or deploy. To specify a List View, you need to use the ListView metadata type.

The format for a ListView member is ObjectName.ListViewApiName.

Here’s an example package.xml to retrieve or deploy the standard “All Accounts” list view on the Account object.

package.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Account.AllAccounts</members>
        <name>ListView</name>
    </types>
    <version>61.0</version>
</Package>

In this example:

  • Account is the API name of the sObject.
  • AllAccounts is the API Name (Developer Name) of the List View.
  • The <name> tag specifies the metadata type, which is ListView.

Output:

<?xml version="1.0" encoding="UTF-8"?>
<ListView xmlns="http://soap.sforce.com/2006/04/metadata">
    <fullName>AllAccounts</fullName>
    <columns>ACCOUNT.NAME</columns>
    <columns>ACCOUNT.SITE</columns>
    <columns>ACCOUNT.ADDRESS1_STATE</columns>
    <columns>ACCOUNT.PHONE1</columns>
    <columns>ACCOUNT.TYPE</columns>
    <columns>CORE.USERS.ALIAS</columns>
    <filterScope>Everything</filterScope>
    <label>All Accounts</label>
    <sharedTo>
        <allInternalUsers></allInternalUsers>
    </sharedTo>
</ListView>

1. The Root Element: <ListView>

<ListView xmlns="http://soap.sforce.com/2006/04/metadata">
...
</ListView>
  • <ListView>: This is the main container tag that declares the metadata type as a ListView.
  • xmlns: This XML Namespace attribute is standard for Salesforce metadata. It tells the Salesforce platform how to interpret the tags within this file, ensuring it conforms to the correct schema.

2. The API Name: <fullName>

XML

<fullName>AllAccounts</fullName>
  • Purpose: This is the unique API Name (also known as the Developer Name) for the List View on its specific object. It cannot contain spaces or certain special characters.
  • In Context: When you reference this List View in your package.xml, you combine the Object name with this fullName. For this example, that’s Account.AllAccounts.

3. The Display Columns: <columns>

<columns>ACCOUNT.NAME</columns>
<columns>ACCOUNT.SITE</columns>
...
<columns>CORE.USERS.ALIAS</columns>
  • Purpose: Each <columns> tag represents a single column displayed in the List View, listed in the order they will appear from left to right.
  • Syntax: The format is typically OBJECT_API_NAME.FIELD_API_NAME.
    • ACCOUNT.NAME refers to the Account Name field on the Account object.
    • ACCOUNT.PHONE1 refers to the Phone field on the Account object.
  • Special Syntax: Notice CORE.USERS.ALIAS. This syntax is used for fields on a related standard object. In this case, it refers to the Alias of the User who owns the Account record (i.e., the Account Owner’s Alias).

4. The Filter Scope: <filterScope>

<filterScope>Everything</filterScope>
  • Purpose: This critical tag defines the base set of records the List View will operate on, corresponding to the “Filter by Owner” radio buttons in the UI.
  • Common Values:
    • Everything: “All accounts” – Shows all records the user has permission to see.
    • Mine: “My accounts” – Shows only records owned by the current user.
    • MyTerritory: Shows records in the user’s territory (for territory management).
    • MyTeamTerritory: Shows records in the user’s team’s territory.
    • Queue: Used for List Views on objects assigned to a Queue.

5. The Display Name: <label>

<label>All Accounts</label>
  • Purpose: This is the user-friendly name that appears in the List View dropdown menu in the Salesforce UI. Unlike <fullName>, the <label> can contain spaces and special characters.

6. The Visibility Settings: <sharedTo>

<sharedTo>
    <allInternalUsers></allInternalUsers>
</sharedTo>
  • Purpose: This block determines who can see and use this List View.
  • <allInternalUsers>: This specific tag makes the List View visible to all internal Salesforce users. This corresponds to the “Visible to all users” setting in the UI.
  • Other Sharing Options: Instead of <allInternalUsers>, you could define more granular sharing here with other tags:
    • Share with Public Groups: <group>GroupName</group>
    • Share with Roles: <role>RoleName</role>
    • Share with Roles and Subordinates: <roleAndSubordinates>RoleName</roleAndSubordinates>

For custom objects or custom list views, simply replace the names with the correct API names (e.g., My_Custom_Object__c.My_Custom_View).

Leave a Reply