Files
Queue-Creation/README.md
T
2026-08-21 16:38:06 +00:00

74 lines
3.2 KiB
Markdown

# Queue Metadata Flow Actions
This project contains only the four Apex actions needed by the existing queue-creation Flow:
- `CreateOriginPicklistItem`
- `CreateEmailToCase`
- `CreateCaseAutoResponseRule`
- `CreateListView`
`MetadataApiClient` and `MetadataXml` are shared implementation helpers, not additional Flow actions.
## Required Named Credential
Create a Named Credential named `Salesforce_Metadata` with:
- URL: your org's My Domain URL
- Authentication: OAuth 2.0 to the same Salesforce org
- Generate Authorization Header: enabled
- Principal permissions: API Enabled and Customize Application
The actions call Metadata API v65.0 through this credential.
## Flow action contracts
### Create Origin Picklist Item
Input: `picklistItemName`
Outputs: `caseOrigin`, `metadataFullName`, `created`
The action reads `StandardValueSet.CaseOrigin`, returns an existing case-insensitive match, or appends a value. The API name is generated from the label.
### Create Email-To-Case
Inputs: `routingName`, `emailAddress`, `caseOwnerId`, `caseOrigin`
Outputs: `metadataFullName`, `routingName`, `emailAddress`, `emailToCaseAddress`, `emailRoutingAddressId`, `created`
The owner ID must be a queue `Group`. Priority is always `Medium`. Email-to-Case must already be enabled in Setup. Salesforce sends a verification message for a new routing address; the generated service address can therefore be blank immediately after creation.
### Create Case Auto-Response Rule Entry
Inputs: `autoResponseRuleId` or `autoResponseRuleName`, optional `sortOrder`, `caseOrigin`, `emailTemplateId`
Outputs: `asyncJobId`, `status`, `metadataFullName`
This action is asynchronous because Salesforce requires file-based retrieve/deploy for auto-response rules. Salesforce stores the sort order as the rule-entry sequence in the metadata file; the supplied position inserts there, and a blank position appends the entry. It adds these criteria:
- `Case.Origin` equals the supplied origin
- `Case.ContactEmail` is not blank
- `Case.Status` equals `Active`
- `Case.RecordTypeId` equals `Customer Service`
The sender is `Columbus McKinnon Support <cmcoautoreply@columbusmckinnon.com>`. The email template must be a Classic Email Template in a shared folder. The returned ID identifies the first coordinator job; the retrieve/deploy continuation jobs are visible in Setup's Apex Jobs page.
### Create List View
Inputs: `listViewLabel`, `objectApiName`, `groupId`, `displayColumns`
Outputs: `listViewApiName`, `metadataFullName`, `created`
`displayColumns` is comma-separated and must use Metadata API list-view column names (for example, `CASE.CASE_NUMBER,CASE.SUBJECT,CASE.STATUS`). The action creates or replaces a queue-scoped view and excludes `Resolved`, `Cancelled`, and `Closed` statuses. The queue Group ID is resolved to its developer name for Metadata API use.
## Transaction note
Place each callout action after a transaction boundary if earlier Flow elements create records. In particular, commit the queue and email template before invoking the Email-to-Case or auto-response actions.
## Deploy
```bash
sf project deploy start --manifest manifest/package.xml --target-org YOUR_ORG
sf apex run test --class-names QueueMetadataActionsTest --result-format human --target-org YOUR_ORG
```