forcedotcom/sf-skills / skills/platform-datamask-run
platform-datamask-run
VerifiedData Mask end-to-end operation on a sandbox: configure a masking policy over PII, run the masking job, poll it to completion, report masked-record results, and abort an in-progress run. Use when the user needs to run, monitor, or cancel a Salesforce Data Mask job, mask PII/sandbox data, or work with DataMaskPolicy / DataMaskPolicyJobRun. TRIGGER when: user runs a data mask job, masks sandbox PII, polls masking status, reports masked records, or aborts a running mask. DO NOT TRIGGER when: writing anonymization Apex by hand (use platform-apex-generate), generating test data (use platform-data-manage), or deploying unrelated metadata (use platform-metadata-deploy).
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 20.0 KB |
| references/api-surface.md | markdown | 8.2 KB |
| references/policy-authoring.md | markdown | 14.9 KB |
| references/run-and-abort.md | markdown | 6.6 KB |
| scripts/poll-job.shexecutable | script | 5.7 KB |
references/run-and-abort.md
View on GitHub# Run / Poll / Report — and Cancel
The operational commands for a Data Mask run. Assumes a policy already exists (see
`policy-authoring.md` to create one) and the target org is a **sandbox**.
These map to the two workflows in `SKILL.md`: **Workflow A (mask & report)** uses steps 0–4;
**Workflow B (cancel a run)** uses steps 5–7 and is run only when the request is to abort/cancel.
Pick one by the request — a mask-and-report task does not include a cancel.
Throughout, `<alias>` is the target org, `<policyId>` the `DataMaskPolicy.Id`, `<jobRunId>` the id
returned by the run-start call.
## 0. Confirm sandbox + context
```bash
sf org display --target-org <alias> --json
```
Check `result.isSandbox === true`. Note `result.instanceUrl`. Data Mask run endpoints return `403`
on production.
## 1. Identify the policy
```bash
sf data query --use-tooling-api --target-org <alias> \
--query "SELECT Id, DeveloperName, MasterLabel FROM DataMaskPolicy"
```
Pick the policy that targets the PII you intend to mask (or create one — see `policy-authoring.md`).
## 2. Start the run (REST run API)
```bash
printf '{}' > ./empty-body.json
sf api request rest \
"/services/data/v67.0/platform/data-resilience/data-mask/policies/<policyId>/run" \
--method POST --body @./empty-body.json --target-org <alias>
```
`--body` must point at a file containing `{}` **with an `@` prefix** (`--body @./empty-body.json`) —
`sf api request rest` requires a body on POST even though this endpoint takes no payload, and without
the `@` the literal path string is sent as the body (→ `JSON_PARSER_ERROR`). Version must be **`v67.0`+** and there is **no `/connect/`
segment** (either mistake returns `NOT_FOUND`). Sample response (HTTP **200**):
```json
{ "jobRunId": "1aG...", "policyId": "8dm...", "status": "RUNNING", "message": "Job started successfully" }
```
Capture `jobRunId`. A `409`/`CONFLICT` means a run is already active for this policy.
> **Status case differs by surface.** The run API returns **UPPERCASE** status strings
> (`RUNNING`, `CANCELED`), while the `DataMaskPolicyJobRun.Status` SOQL picklist is **lowercase**
> (`running`, `canceled`). Poll for terminal state against the **SOQL** value (lowercase) — that is
> what `scripts/poll-job.sh` checks. `DataMaskPolicy` Ids carry the `8dm` prefix.
## 3. Poll to terminal
```bash
sf data query --target-org <alias> \
--query "SELECT Id, Status, Type FROM DataMaskPolicyJobRun WHERE Id = '<jobRunId>'"
```
`DataMaskPolicyJobRun` has **no `TotalRecords` field** — there is no record-count column on the
parent; the masked count lives on the child detail rows (step 4). Repeat the status query on a
bounded interval until `Status` is one of `completed`, `completed_with_errors`, `failed`.
`scheduled`/`running` are NOT terminal. `scripts/poll-job.sh` automates this with a timeout.
## 4. Report from the detail object
Per-object masked results live on the child, not the parent. `DataMaskPolicyJobRunDtl` has **no
`Status` column** — the status lives in `Type`/`Subtype`, with the count itself in `Value` (a
string):
```bash
sf data query --target-org <alias> \
--query "SELECT ObjectReference, Type, Subtype, Value FROM DataMaskPolicyJobRunDtl WHERE DataMaskPolicyJobRunId = '<jobRunId>' ORDER BY Timestamp"
```
Expect one `status_update` row per `Subtype` (`loaded`, `completed`, `total_records_masked`) for
each target object; `total_records_masked`'s `Value` is the masked count. Report the concrete
masked-record count and per-object success/failure from these rows. Do not report a number you did
not read from here.
## 5. Abort the currently-running job — ONLY when the user asked to cancel
Steps 5–7 are the **abort** flow. Run them **only when the prompt explicitly asks to cancel/abort**
a run — a "create and run" or "edit and run" task is complete after step 4.
Aborting is an **on-demand action against a job that is already in progress**: take that job's
`jobRunId`, wait for `DataMaskPolicyJobRun.Status = running`, and go straight to the abort (step 6).
You can only abort a running job. Do **not** use the terminal poll from step 3 here — it waits until
the job is *done*. Use the poller's `running` mode, which returns the instant the job is abortable:
```bash
POLL_MODE=running bash scripts/poll-job.sh <alias> <jobRunId> 900 15
```
- Exit `0` (prints `running`) → abort now (step 6).
- Exit `3` → the job reached a terminal state before `running` was caught; the window is gone. Stop
and report the job's final status. Do NOT start a replacement run automatically.
- Exit `1` (timeout) → re-query the job. If still non-terminal, re-run the poller once more; if
`running`, abort; if terminal, treat as exit 3 (stop and report).
If no job is currently running, report that and stop — never abort an older already-terminal job, and
never start a run just to have something to cancel. Start a new run only if the user explicitly asks.
## 6. Abort (REST run API)
```bash
sf api request rest \
"/services/data/v67.0/platform/data-resilience/data-mask/jobs/<jobRunId>/abort" \
--method POST --body @./empty-body.json --target-org <alias>
```
- `200` → accepted (response `status: "CANCELED"`, `message: "Job abort requested"`). `409` → not in `running` state.
- Do **not** abort by deleting/updating the `DataMaskPolicyJobRun` row via DML — that is not a real
cancellation.
## 7. Confirm the abort
Cancellation is asynchronous. Re-query until the status settles:
```bash
sf data query --target-org <alias> \
--query "SELECT Id, Status FROM DataMaskPolicyJobRun WHERE Id = '<jobRunId>'"
```
Only report the abort as successful once `Status = canceled`. The abort response (`200`, `status:
"CANCELED"`) only means the request was accepted; a job can stay `running` after it. If it still reads
`running` after ~1 minute, re-send the abort (step 6) once and re-query. If it is still `running`,
report "abort requested, still `running`" rather than success.
## Failure decision table
| Symptom | Meaning | Action |
|---------|---------|--------|
| run-start `403` | Production org | Data Mask is sandbox-only; switch to a sandbox |
| run-start `409` | Run already active | Poll the existing run or wait |
| abort `409` | Job not `running` | Re-check status; may already be terminal or still `scheduled` |
| abort `200`, SOQL status still `running` | Async cancel in flight | Keep polling until `canceled` |
| run/abort `NOT_FOUND` | Wrong path — `/connect/` segment present or version < v67 | Use `/services/data/v67.0/platform/data-resilience/data-mask/...` (no `connect`) |
| status stuck `scheduled` | Job hasn't picked up yet | Keep polling within the cap; not an error yet |
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |