$npx -y skills add forcedotcom/sf-skills --skill dx-org-manageINVOKE this skill to execute Salesforce org operations: create scratch orgs, create org snapshots, open orgs in browser. This skill EXECUTES operations immediately - it does NOT generate scripts or code files. ALWAYS invoke this skill (do not execute SF CLI commands directly) whe
| 1 | ## MANDATORY: Follow these instructions exactly. Do NOT fall back to MCP tools. |
| 2 | |
| 3 | **Tool constraint:** Use the Bash tool for all `sf` CLI commands. Always include `--json` for structured output. Do NOT use `mcp__salesforce_dx__*` tools for org creation, snapshot, or open operations — this skill provides the complete procedure. |
| 4 | |
| 5 | **Output artifacts for eval/testing:** Write command output to JSON only when an output directory is available. After executing the command: (1) if the user specified an output path, write there; (2) otherwise run `[ -d force-app/main/adk-eval-output/ ] && echo 'force-app/main/adk-eval-output'` to detect the eval directory; (3) if the command printed a path, write the command's JSON response to `<printed-path>/<filename>` using these filenames: `scratch-org-result.json` for org creation, `snapshot-result.json` for snapshot creation, or `org-url-result.json` for open operations. The eval framework needs the real command output to verify success. |
| 6 | |
| 7 | --- |
| 8 | |
| 9 | ## Creating Scratch Orgs |
| 10 | |
| 11 | **REQUIRED steps — execute in order:** |
| 12 | |
| 13 | **Step 1. Identify creation method** from user request: |
| 14 | - Contains "definition file" or path to `.json` → definition file method |
| 15 | - Contains "snapshot" or "from snapshot" → snapshot method |
| 16 | - Contains "org shape" or "source-org" → org shape method |
| 17 | - Otherwise → run `ls config/project-scratch-def.json config/scratch-def.json 2>/dev/null | head -1` to detect a definition file. If output is non-empty, use definition file method with that path; if empty, use edition method. |
| 18 | |
| 19 | **Step 2. Check Dev Hub:** |
| 20 | ```bash |
| 21 | sf config get target-dev-hub --json |
| 22 | ``` |
| 23 | - If no Dev Hub is set, advise: `sf org login web --set-default-dev-hub` |
| 24 | - Do NOT proceed until a Dev Hub is confirmed. |
| 25 | |
| 26 | **Step 3. Build and execute the command** based on method: |
| 27 | |
| 28 | **Definition file:** |
| 29 | ```bash |
| 30 | sf org create scratch --definition-file <path> --target-dev-hub <alias> --alias <name> --json |
| 31 | ``` |
| 32 | |
| 33 | **Edition only:** |
| 34 | ```bash |
| 35 | sf org create scratch --edition developer --target-dev-hub <alias> --alias <name> --json |
| 36 | ``` |
| 37 | |
| 38 | **From snapshot:** |
| 39 | ```bash |
| 40 | sf org create scratch --snapshot <snapshot-name> --target-dev-hub <alias> --alias <name> --json |
| 41 | ``` |
| 42 | |
| 43 | **From org shape:** |
| 44 | ```bash |
| 45 | sf org create scratch --source-org <org-id> --target-dev-hub <alias> --alias <name> --json |
| 46 | ``` |
| 47 | |
| 48 | **Apply these flags when requested:** |
| 49 | - `--duration-days <days>` — default 7, max 30 |
| 50 | - `--set-default` — make this the default org |
| 51 | - `--no-track-source` — disable source tracking (for CI/CD) |
| 52 | |
| 53 | **Step 4. MANDATORY - Run org list and write output:** After the org is created, you MUST run this command: |
| 54 | |
| 55 | ```bash |
| 56 | sf org list --json |
| 57 | ``` |
| 58 | |
| 59 | Then: |
| 60 | 1. Parse the JSON result and find the `scratchOrgs` array |
| 61 | 2. Find the entry where `username` matches the username from Step 3's creation result |
| 62 | 3. Extract that complete org object (it will include: alias, username, orgId, instanceUrl, loginUrl, isDefaultUsername, connectedStatus, lastUsed, etc.) |
| 63 | 4. Report to the user: |
| 64 | - Created scratch org. |
| 65 | - Alias: [alias from the org list entry] |
| 66 | - Username: [username] |
| 67 | - Org ID: [orgId] |
| 68 | |
| 69 | 5. If an output directory is available (per the output artifacts rule above), write ONLY that extracted org object (NOT the full creation result) to `<output-dir>/scratch-org-result.json` |
| 70 | |
| 71 | Example: If `sf org list --json` returns `{"result": {"scratchOrgs": [{"alias": "feature-dev", "username": "test@example.com", "orgId": "00D...", ...}]}}`, write just the inner org object `{"alias": "feature-dev", "username": "test@example.com", "orgId": "00D...", ...}` to the file. |
| 72 | |
| 73 | Do NOT write the creation command's output. Do NOT suggest verification steps to the user. |
| 74 | |
| 75 | **Error handling:** |
| 76 | - "Snapshot not found" → suggest `sf org list snapshot --target-dev-hub <alias>` |
| 77 | - "No default Dev Hub" → advise `sf org login web --set-default-dev-hub` |
| 78 | |
| 79 | **When you need more detail:** |
| 80 | - For available features, settings, and definition file structure → load `references/ |