Retrieve Assignment Rules with package.xml

How to retrieve Assignment Rules With package.xml

Retrieve Assignment Rules in Salesforce
How to retrieve Assignment Rules

Syntax to retrieve assignment rules with package.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <name>AssignmentRule</name>
        <members>Case.Custom Rules</members>
    </types>
    <version>62.0</version>
</Package>

Note: Use Object and Rule name in members. There is no limit in retrieving members.

What is AssignmentRule in Salesforce?

Assignment rules decide which user or queue a new Lead or Case is assigned to. Retrieving them lets you review the rule entries, compare orgs, or deploy the rules to another environment.

Steps to retrieve it in VS Code

  1. Open your Salesforce DX project in VS Code and authorize your org with SFDX: Authorize an Org.
  2. Open manifest/package.xml, or create the file, and paste the XML shown above.
  3. Right-click package.xml and choose SFDX: Retrieve Source in Manifest from Org.
  4. When the command finishes, open the folder force-app/main/default/assignmentRules to see the retrieved files.

Each member is written as ObjectName.RuleName, for example Case.Custom Rules. Use the exact name shown in Setup. Assignment rules exist only for Lead and Case.

Retrieve it with the Salesforce CLI

If you prefer the terminal, run one of these commands from your project folder:

sf project retrieve start --manifest manifest/package.xml
sf project retrieve start --manifest manifest/package.xml

Where the files are saved

After a successful retrieve, the files are placed inside your project, for example in force-app/main/default/assignmentRules/Case.assignmentRules-meta.xml.

Common problems and fixes

  • Entity of type AssignmentRule cannot be found: check the spelling and the API name of the member, and make sure you are authorized to the correct org.
  • Nothing was retrieved: run sf org list to confirm the default org, and check that the component actually exists there.
  • API version: the examples use version 62.0. You can use a higher version if your org supports it.

FAQ

Which objects support assignment rules?
Only Lead and Case.

Can I retrieve several rules at once?
Yes. Add one members line for each rule, or use the AssignmentRules type with the object name to retrieve all rules of that object.

Leave a Reply