life-sciences-kam-coordinate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Life Sciences Cloud KAM End-to-End Orchestrator

Life Sciences Cloud KAM端到端编排器

Runs the complete Life Sciences Cloud setup for a key account management (KAM) user as six stages in strict sequence, gating each on the previous stage's success. Each stage delegates to a child skill or reference workflow (see Execution Order).
按严格顺序运行针对关键客户管理(KAM)用户的完整Life Sciences Cloud设置流程,分为六个阶段,每个阶段的推进均依赖于前一阶段的成功。每个阶段会委托给子Skill或参考工作流(详见执行顺序)。

Scope Guard (evaluate FIRST)

范围校验(优先执行)

Serve only requests for the full end-to-end LSC setup for a KAM user. A single stage/phase/step is never invokable here — never silently expand a partial ask into the whole flow. Before any work:
  • Field sales rep persona (not KAM) → redirect to
    life-sciences-fieldsalesrep-coordinate
    ; stop.
  • Unrelated to LSC setup (at start or mid-run) → do not attempt it; say you did not understand and show what you can help with (full end-to-end LSC KAM setup, or standalone
    life-sciences-prerequisites-validate
    /
    life-sciences-territory-configure
    ); stop.
  • Single stage with its own standalone skill — prerequisites (1) or territory config (3) → redirect to that skill; stop.
  • Single stage with no standalone skill — config deploy (2), participant role/sprint (4), data and plan templates (5), user provisioning (6) → explain these run only inside the full flow; stop. Do not launch the full flow unless the user then asks.
Continue only for the complete end-to-end KAM setup: the full flow in order with gates, each stage's work delegated to child skills / reference files.

仅处理针对KAM用户的完整LSC端到端设置请求。绝不允许单独调用单个阶段/环节/步骤——切勿将部分请求自动扩展为完整流程。在开展任何工作前:
  • 现场销售代表角色(非KAM)→ 重定向至
    life-sciences-fieldsalesrep-coordinate
    ;终止流程。
  • 与LSC设置无关(流程启动时或运行中)→ 请勿尝试执行,告知用户无法理解请求并展示可提供的帮助(完整LSC KAM端到端设置,或独立的
    life-sciences-prerequisites-validate
    /
    life-sciences-territory-configure
    );终止流程。
  • 拥有独立Skill的单个阶段——先决条件(1)或区域配置(3)→ 重定向至对应Skill;终止流程。
  • 无独立Skill的单个阶段——配置部署(2)、参与者角色/冲刺(4)、数据与计划模板(5)、用户配置(6)→ 说明这些仅能在完整流程内运行;终止流程。除非用户后续明确要求,否则不得启动完整流程。
仅在用户请求完整KAM端到端设置时继续执行:按顺序运行带依赖校验的完整流程,每个阶段的工作委托给子Skill/参考文件。

Required Inputs

必要输入

  • Target org: the org to deploy to — selected by the user from connected orgs or a freshly authenticated org (Phase 0). Never assume a default org silently; the user confirms or selects it before any stage runs.

  • 目标组织:要部署的组织——由用户从已连接组织或新认证的组织中选择(第0阶段)。切勿默认使用某个组织;在任何阶段运行前,需由用户确认或选择目标组织。

Execution Order (MANDATORY)

执行顺序(强制要求)

Terminology: Stage = one of the 6 units of work, each delegated to a child skill/reference; Phase = a named group inside a stage; Step = an atomic action inside a phase.
Run in this order, each gated on the previous (dependency diagram in
references/orchestration-flow.md
):
#StageRunsGate (must pass to advance)Output
Setup: download
.lsc-starter-config/LSStarterConfig
Folder present (MANDATORY — hard stop)Shared source folder in CWD
1Prerequisites Validation
life-sciences-prerequisites-validate
skill
All prerequisites PASSOrg confirmed ready
2Starter Config Deploy
references/stage-2-starter-config-overview.md
13 deploy steps + KAM config records succeedLSC Custom Profile + KAM/Sprint settings
3Territory Configuration
life-sciences-territory-configure
skill
Territory model Active + L3 territoryLevel-3 territory ID + name
4Participant Role & Sprint
references/stage-4-participant-role-and-sprint.md
Participant role + sprint createdRole + Sprint IDs
5KAM Data & Plan Templates
references/stage-5-data-and-plan-templates-overview.md
Account/HCP/product/territory data created + goals, template (Final), items, assignment created + goals/template/PATI shared to the leaf territoryAccount + product master data + published ActionPlanTemplate
6KAM User Provisioning
references/stage-6-user-provisioning-overview.md
User created, permsets + territory assigned; metadata cache generatedKAM username

术语定义: Stage(阶段) = 6个工作单元之一,每个单元委托给子Skill/参考文件;Phase(环节) = 阶段内的命名分组;Step(步骤) = 环节内的原子操作。
按以下顺序运行,每个阶段均依赖前一阶段的成功(依赖关系图见
references/orchestration-flow.md
):
#阶段运行内容校验条件(必须通过才能推进)输出
准备工作:下载
.lsc-starter-config/LSStarterConfig
文件夹已存在(强制要求——未满足则终止)当前工作目录下的共享源文件夹
1先决条件验证
life-sciences-prerequisites-validate
Skill
所有先决条件通过确认组织已就绪
2初始配置部署
references/stage-2-starter-config-overview.md
13个部署步骤 + KAM配置记录执行成功LSC自定义配置文件 + KAM/冲刺设置
3区域配置
life-sciences-territory-configure
Skill
区域模型已激活 + 三级区域存在三级区域ID + 名称
4参与者角色与冲刺创建
references/stage-4-participant-role-and-sprint.md
参与者角色 + 冲刺已创建角色 + 冲刺ID
5KAM数据与计划模板创建
references/stage-5-data-and-plan-templates-overview.md
客户/HCP/产品/区域数据已创建 + 目标、模板(最终版)、任务、分配已创建 + 目标/模板/PATI已共享至叶子区域客户 + 产品主数据 + 已发布的ActionPlanTemplate
6KAM用户配置
references/stage-6-user-provisioning-overview.md
用户已创建,权限集 + 区域已分配;元数据缓存已生成KAM用户名

Workflow

工作流

Phase 0 — Org Selection (MANDATORY, runs first)

第0环节——组织选择(强制要求,优先运行)

Establish which org to use every time — never silently reuse the default org.
  1. List connected orgs with
    sf org list --json
    , then present the authenticated (non-expired) orgs as a numbered list (alias, username, org type, default marker), plus an option N to log in to a fresh org.
  2. Ask the user to choose a number or N.
  3. Handle the selection:
    • Existing org → capture its username/alias as the target org.
    • Fresh org (N) → ask for the login URL (
      https://login.salesforce.com
      ,
      https://test.salesforce.com
      , or a My Domain URL) and an alias, then run the login command yourself:
      sf org login web --instance-url <url> --alias <alias> --set-default
      . Do not hand the command to the user to run — execute it directly. It opens a browser on the user's machine for them to complete the login interactively; the command then returns. After it finishes, re-run
      sf org list --json
      to confirm.
  4. Confirm the target org back to the user and store it in
    OrchestrationState.targetOrg
    .
If
sf org list
returns no authenticated orgs, go straight to the fresh-org login (option N).
每次都要确认使用哪个组织——切勿默认复用之前的组织。
  1. 列出已连接组织:执行
    sf org list --json
    ,然后将已认证(未过期)的组织以编号列表形式展示(别名、用户名、组织类型、默认标记),同时提供选项N用于登录新组织。
  2. 请求用户选择:让用户选择编号或N
  3. 处理选择
    • 现有组织 → 捕获其用户名/别名作为目标组织。
    • 新组织(N) → 请求登录URL(
      https://login.salesforce.com
      https://test.salesforce.com
      或自定义域名URL)和别名,然后自行运行登录命令
      sf org login web --instance-url <url> --alias <alias> --set-default
      。请勿让用户自行运行命令——直接执行该命令。命令会在用户机器上打开浏览器,供用户完成交互式登录;登录完成后命令返回。执行完成后,重新运行
      sf org list --json
      确认登录成功。
  4. 向用户确认目标组织并将其存储在
    OrchestrationState.targetOrg
    中。
如果
sf org list
未返回任何已认证组织,直接进入新组织登录流程(选项N)。

Phase 1 — Introduction and Confirmation

第1环节——介绍与确认

  1. Present the workflow to the user — a "Life Sciences Cloud — Full KAM Setup Workflow" header, the target org, and the 6 stages in order with a one-line summary each: (1) Validate Prerequisites; (2) Deploy Starter Configuration (objects, profiles, config records incl. KAM & Sprint settings, layouts, flexipages); (3) Configure Territories; (4) Create Participant Role & Sprint; (5) Create KAM Data & Plan Templates (account, provider, product, territory data + goals, tasks, measures, published action plan template); (6) Provision KAM User (profile/permsets/territory + mobile metadata cache).
  2. Ask for confirmation: "Ready to begin the full LSC KAM setup? (yes/no)"
  3. Download the shared source folder FRESH (MANDATORY — hard gate, before any stage). Stages 2 (metadata + config records) and 5 (Data CSVs) read from
    .lsc-starter-config/LSStarterConfig/
    ; those stages do NOT download or delete it — the orchestrator owns one fresh download here and one delete in Phase 9. Always re-pull — never reuse an existing folder (a stale copy would skip newly added components). Delete any pre-existing
    .lsc-starter-config
    first, then sparse-checkout the subtree fresh:
    bash
    rm -rf .lsc-starter-config lsstarter-tmp
    git clone --no-checkout --depth 1 --filter=blob:none \
      https://github.com/SalesforceLabs/LSStarterConfig.git lsstarter-tmp
    cd lsstarter-tmp && git sparse-checkout init --cone \
      && git sparse-checkout set Codey/LSStarterConfig && git checkout && cd ..
    mv lsstarter-tmp/Codey ./.lsc-starter-config && rm -rf lsstarter-tmp
    .lsc-starter-config/LSStarterConfig/
    has its own
    sfdx-project.json
    (pins
    sourceApiVersion: 65.0
    ) — deploy steps must run from inside it.
  4. Download gate — verify before proceeding. Confirm
    .lsc-starter-config/LSStarterConfig/sfdx-project.json
    and
    .lsc-starter-config/LSStarterConfig/Data/
    exist (e.g.
    ls .lsc-starter-config/LSStarterConfig/sfdx-project.json .lsc-starter-config/LSStarterConfig/Data
    ).
    • If present → set
      sourceFolderDownloaded: true
      and proceed to Phase 2.
    • If missing/failed → STOP. Do NOT proceed to any stage — every stage depends on this folder. Report the failure (likely: no network / GitHub unreachable, git < 2.25, or disk/permission), leave
      sourceFolderDownloaded: false
      , and do not advance. Fix the cause and re-run, or download the folder manually into the CWD.
  1. 向用户展示工作流:显示标题"Life Sciences Cloud — 完整KAM设置工作流",展示目标组织,以及6个阶段的顺序和每个阶段的一行摘要:(1) 验证先决条件;(2) 部署初始配置(对象、配置文件、包含KAM与冲刺设置的配置记录、布局、Flexipage);(3) 配置区域;(4) 创建参与者角色与冲刺;(5) 创建KAM数据与计划模板(客户、医疗服务提供者、产品、区域数据 + 目标、任务、指标、已发布的行动计划模板);(6) 配置KAM用户(配置文件/权限集/区域 + 移动元数据缓存)。
  2. 请求确认:"是否准备开始完整的LSC KAM设置?(是/否)"
  3. 重新下载共享源文件夹(强制要求——硬校验,在任何阶段前执行)。阶段2(元数据 + 配置记录)和阶段5(数据CSV)会读取
    .lsc-starter-config/LSStarterConfig/
    ;这些阶段不会下载或删除该文件夹——编排器仅在此处下载一次,并在第9环节删除一次。始终重新拉取——切勿复用现有文件夹(过期副本会跳过新增组件)。先删除任何已存在的
    .lsc-starter-config
    ,然后通过稀疏检出重新拉取子树:
    bash
    rm -rf .lsc-starter-config lsstarter-tmp
    git clone --no-checkout --depth 1 --filter=blob:none \
      https://github.com/SalesforceLabs/LSStarterConfig.git lsstarter-tmp
    cd lsstarter-tmp && git sparse-checkout init --cone \
      && git sparse-checkout set Codey/LSStarterConfig && git checkout && cd ..
    mv lsstarter-tmp/Codey ./.lsc-starter-config && rm -rf lsstarter-tmp
    .lsc-starter-config/LSStarterConfig/
    包含自己的
    sfdx-project.json
    (固定
    sourceApiVersion: 65.0
    )——部署步骤必须在该目录内运行。
  4. 下载校验——继续前验证。确认
    .lsc-starter-config/LSStarterConfig/sfdx-project.json
    .lsc-starter-config/LSStarterConfig/Data/
    存在(例如执行
    ls .lsc-starter-config/LSStarterConfig/sfdx-project.json .lsc-starter-config/LSStarterConfig/Data
    )。
    • 若存在 → 设置
      sourceFolderDownloaded: true
      并推进至第2环节。
    • 若缺失/下载失败 → 终止流程,不得进入任何阶段——所有阶段都依赖该文件夹。报告失败原因(可能是:无网络/GitHub无法访问、git版本低于2.25、磁盘/权限问题),设置
      sourceFolderDownloaded: false
      ,不再推进。修复问题后重新运行,或手动将文件夹下载至当前工作目录。

Phase 2 — Execute Stage 1: Prerequisites Validation

第2环节——执行阶段1:先决条件验证

  1. Run the prerequisites validation following the
    life-sciences-prerequisites-validate
    skill workflow exactly.
  2. Gate check: If ALL prerequisites pass → proceed to Stage 2. If ANY fails → stop, present the failure table, and ask: "Continue anyway (skip failed prerequisites), or stop and fix them first?" Stop → end the workflow. Continue → proceed with a warning that later stages may fail.
  1. 严格按照
    life-sciences-prerequisites-validate
    Skill的工作流运行先决条件验证
  2. 校验检查:若所有先决条件通过 → 推进至阶段2。若有任何一项失败 → 终止流程,展示失败列表,并询问:"是否继续(跳过失败的先决条件),还是先终止并修复问题?"选择终止 → 结束工作流。选择继续 → 推进流程并警告后续阶段可能失败。

Phase 3 — Execute Stage 2: Starter Config Deploy

第3环节——执行阶段2:初始配置部署

  1. Run the starter config deployment following
    references/stage-2-starter-config-overview.md
    exactly (all 13 deploy steps + the KAM/Sprint config-record edits); read its own reference files as directed. The KAM adaptation deploys only the KAM-relevant layouts (4) and flexipages (6) — all of them, automatically, with no selection prompt — and confirms the StandardValueSet picklist values with the admin (three business-framed groups) BEFORE deploying them, then writes those confirmed values into the
    KAMSettings_OrgLevel
    and
    SprintSettings_OrgLevel
    config records.
  2. Gate check: Verify the LSC Custom Profile exists:
    bash
    sf data query --query "SELECT Id, Name FROM Profile WHERE Name = 'LSC Custom Profile'" --target-org <org> --json
    • If profile exists → proceed to Stage 3. If not found → stop and report deployment failure.
  1. 严格按照
    references/stage-2-starter-config-overview.md
    运行初始配置部署
    (所有13个部署步骤 + KAM/冲刺配置记录编辑);按指引读取其参考文件。KAM适配仅部署与KAM相关的布局(4个)和Flexipage(6个)——全部自动部署,无选择提示——并在部署前与管理员确认StandardValueSet选择列表的值(三个业务分组),然后将确认后的值写入
    KAMSettings_OrgLevel
    SprintSettings_OrgLevel
    配置记录。
  2. 校验检查:验证LSC自定义配置文件存在:
    bash
    sf data query --query "SELECT Id, Name FROM Profile WHERE Name = 'LSC Custom Profile'" --target-org <org> --json
    • 若配置文件存在 → 推进至阶段3。若未找到 → 终止流程并报告部署失败。

Phase 4 — Execute Stage 3: Territory Configuration

第4环节——执行阶段3:区域配置

  1. Run the territory configuration following the
    life-sciences-territory-configure
    skill workflow exactly. If an active territory model already exists, use it and show the hierarchy rather than creating a new one.
  2. Gate check: Verify the territory model is Active and a level-3 territory exists:
    bash
    sf data query --query "SELECT Id, Name, DeveloperName, Territory2Model.State FROM Territory2 WHERE ParentTerritory2.ParentTerritory2Id != null AND Territory2Model.State = 'Active'" --target-org <org> --json
    • If found → capture the level-3 territory ID + name (
      OrchestrationState.territoryId
      ) and tell the user this leaf territory is the single territory reused for Stage 5 (ProductTerritoryAvailability) and Stage 6 (UserTerritory2Association for both admin and KAM user). Proceed to Stage 4.
    • If not found → stop and report the issue.
  1. 严格按照
    life-sciences-territory-configure
    Skill的工作流运行区域配置
    。若已存在激活的区域模型,直接使用该模型并展示层级结构,无需创建新模型。
  2. 校验检查:验证区域模型已激活且存在三级区域:
    bash
    sf data query --query "SELECT Id, Name, DeveloperName, Territory2Model.State FROM Territory2 WHERE ParentTerritory2.ParentTerritory2Id != null AND Territory2Model.State = 'Active'" --target-org <org> --json
    • 若找到 → 捕获三级区域ID + 名称
      OrchestrationState.territoryId
      )并告知用户该叶子区域将在阶段5(ProductTerritoryAvailability)和阶段6(UserTerritory2Association,针对管理员和KAM用户)中复用。推进至阶段4。
    • 若未找到 → 终止流程并报告问题。

Phase 5 — Execute Stage 4: Participant Role & Sprint

第5环节——执行阶段4:参与者角色与冲刺创建

  1. Create the participant role and sprint following
    references/stage-4-participant-role-and-sprint.md
    exactly. Only the
    MasterLabel
    /
    Name
    fields are confirmed with the admin; all other fields are auto-derived and shown for confirmation.
  2. Gate check: Verify a
    ParticipantRole
    (
    DeveloperName = 'Rep_Execution_Specialist'
    ,
    IsActive = true
    ) and a
    Sprint
    (Status
    Not Started
    ) exist. If either is missing → stop and report.
  1. 严格按照
    references/stage-4-participant-role-and-sprint.md
    创建参与者角色与冲刺
    。仅与管理员确认
    MasterLabel
    /
    Name
    字段;所有其他字段自动推导并展示供确认。
  2. 校验检查:验证存在
    ParticipantRole
    DeveloperName = 'Rep_Execution_Specialist'
    IsActive = true
    )和
    Sprint
    (状态为
    Not Started
    )。若其中任何一项缺失 → 终止流程并报告。

Phase 6 — Execute Stage 5: KAM Data & Plan Templates

第6环节——执行阶段5:KAM数据与计划模板创建

Both parts run as the admin, in order, from the single reference
references/stage-5-data-and-plan-templates-overview.md
(Part A = data, Part B = plan templates).
  1. Create the KAM data (Part A) following the reference exactly. Pass the Stage-3 level-3 territory. Creates (from the Data CSVs): Account, HealthcareProvider, ObjectTerritory2Association, ProviderAcctTerritoryInfo, Product2, LifeSciMarketableProduct, ContactPointAddress, ProductTerritoryAvailability.
  2. Part A gate check: Verify the Account,
    LifeSciMarketableProduct
    , and
    ProductTerritoryAvailability
    (on the Stage-3 territory) exist; capture the
    LifeSciMarketableProduct
    ID (Part B uses it). If any missing → stop.
  3. Create the goals, tasks, measures, and action plan template (Part B) following the same reference exactly (stay on the admin login). Creates 2
    GoalDefinition
    records, a
    GoalDefinitionProduct
    , an
    ActionPlanTemplate
    (+ auto
    ActionPlanTemplateVersion
    ), 3
    ActionPlanTemplateItem
    records, publishes the template (status → Final), creates an
    ActionPlanTemplateAssignment
    , and shares the 2
    GoalDefinition
    records, the
    ActionPlanTemplate
    , and both
    ProviderAcctTerritoryInfo
    records to the Stage-3 leaf-territory Group (5 manual shares total) so the KAM user reaches them through the territory. Only the record names are confirmed with the admin.
  4. Part B gate check: Verify the template is published (a
    Final
    ActionPlanTemplateVersion
    exists), an
    ActionPlanTemplateAssignment
    exists, and the leaf-territory shares exist (2
    GoalDefinitionShare
    + 1
    ActionPlanTemplateShare
    + 2
    ProviderAcctTerritoryInfoShare
    whose
    UserOrGroupId
    is the Stage-3 territory Group). If not → stop.
两部分均以管理员身份运行,按顺序执行,参考同一文件
references/stage-5-data-and-plan-templates-overview.md
(A部分=数据,B部分=计划模板)。
  1. 创建KAM数据(A部分):严格按照参考文件执行。传入阶段3的三级区域。从数据CSV创建:Account、HealthcareProvider、ObjectTerritory2Association、ProviderAcctTerritoryInfo、Product2、LifeSciMarketableProduct、ContactPointAddress、ProductTerritoryAvailability。
  2. A部分校验检查:验证Account、
    LifeSciMarketableProduct
    ProductTerritoryAvailability
    (关联阶段3的区域)已存在;捕获
    LifeSciMarketableProduct
    ID(B部分会用到)。若任何一项缺失 → 终止流程
  3. 创建目标、任务、指标和行动计划模板(B部分):严格按照同一参考文件执行(保持管理员登录状态)。创建2条
    GoalDefinition
    记录、1条
    GoalDefinitionProduct
    、1条
    ActionPlanTemplate
    (+自动生成的
    ActionPlanTemplateVersion
    )、3条
    ActionPlanTemplateItem
    记录,发布模板(状态→Final),创建1条
    ActionPlanTemplateAssignment
    ,并将2条
    GoalDefinition
    记录、
    ActionPlanTemplate
    和2条
    ProviderAcctTerritoryInfo
    记录共享至阶段3的叶子区域(共5次手动共享),以便KAM用户通过区域访问这些记录。仅与管理员确认记录名称
  4. B部分校验检查:验证模板已发布(存在
    Final
    状态的
    ActionPlanTemplateVersion
    )、
    ActionPlanTemplateAssignment
    已存在、叶子区域共享已生效(2条
    GoalDefinitionShare
    + 1条
    ActionPlanTemplateShare
    + 2条
    ProviderAcctTerritoryInfoShare
    ,其
    UserOrGroupId
    为阶段3的区域组ID)。若未满足 → 终止流程

Phase 7 — Execute Stage 6: KAM User Provisioning

第7环节——执行阶段6:KAM用户配置

  1. Provision the KAM user following
    references/stage-6-user-provisioning-overview.md
    exactly. Pass the Stage-3 level-3 territory. Creates a user whose username contains
    kam
    , assigns the permission sets Health Cloud Starter, Life Sciences Key Account Management, Life Sciences Field Sales Representative, and Life Sciences Core, assigns both the admin and the KAM user to the level-3 territory (confirm with admin — MUST be the same territory used for ProductTerritoryAvailability in Stage 5), and generates the mobile metadata cache via the Connect API.
  2. Gate check (STOP-GATE — Stage 6 completeness). Do NOT accept "user created" as passing. Verify the user is
    IsActive=true
    on
    LSC Custom Profile
    , has a
    UserTerritory2Association
    to the Stage-3 territory, the metadata cache reached
    Status='Active'
    , and the assigned-permset count is 4 ({HealthCloudStarter, LifeSciencesKeyAccountManager, LifeSciencesFieldSalesRepresentative, LifeSciencesCore}):
    bash
    sf data query --query "SELECT COUNT(Id) c FROM PermissionSetAssignment WHERE AssigneeId = '<newUserId>' AND PermissionSet.IsOwnedByProfile = false" --target-org <org> --json
    If < 2, or the territory assignment or metadata cache is missing, re-run the missing part before finishing.
  1. 严格按照
    references/stage-6-user-provisioning-overview.md
    配置KAM用户
    。传入阶段3的三级区域。创建用户名包含
    kam
    的用户,分配权限集Health Cloud StarterLife Sciences Key Account ManagementLife Sciences Field Sales RepresentativeLife Sciences Core,将管理员和KAM用户均分配至三级区域(需与管理员确认——必须与阶段5中ProductTerritoryAvailability使用的区域相同),并通过Connect API生成移动元数据缓存。
  2. 校验检查(终止校验——阶段6完整性)。仅确认"用户已创建"不视为通过。验证用户
    IsActive=true
    且使用
    LSC Custom Profile
    、已关联阶段3的区域的
    UserTerritory2Association
    、元数据缓存状态为
    Status='Active'
    、已分配的权限集数量为4({HealthCloudStarter, LifeSciencesKeyAccountManager, LifeSciencesFieldSalesRepresentative, LifeSciencesCore}):
    bash
    sf data query --query "SELECT COUNT(Id) c FROM PermissionSetAssignment WHERE AssigneeId = '<newUserId>' AND PermissionSet.IsOwnedByProfile = false" --target-org <org> --json
    若数量小于2,或区域分配/元数据缓存缺失,重新运行缺失部分后再结束流程。

Phase 8 — Final Summary, Cleanup & On-Device Validation

第8环节——最终总结、清理与设备端验证

  1. Display the complete workflow summary — a "Life Sciences Cloud KAM Setup Complete" header, then one block per stage with actual values: (1) prerequisites confirmed; (2) objects/profiles/config records deployed, KAM & Sprint settings written, layouts + flexipages, 28 trigger handlers; (3) Territory Model
    <model>
    (Active) + Level-3
    <territory>
    ; (4) Participant Role
    Rep Execution Specialist
    + Sprint
    <name>
    ; (5) Account + HCP, product master data, ProductTerritoryAvailability on
    <territory>
    , 2 Goal Definitions, ActionPlanTemplate
    <name>
    (Final) + 3 items + assignment, goals + template + 2 PATI shared to territory
    <territory>
    ; (6) User
    <name>
    (
    <username>
    ) on
    LSC Custom Profile
    , permsets Health Cloud Starter + Life Sciences Key Account Management + Life Sciences Field Sales Representative + Life Sciences Core, Territory
    <territory>
    (admin + KAM), mobile metadata cache generated. Close: "The org is ready for Life Sciences Cloud key account management workflows."
  2. Cleanup — delete the shared source folder ONCE. After the final summary (all 6 stages complete), run from the CWD:
    bash
    rm -rf .lsc-starter-config
    Do this silently — do NOT print a cleanup line or mention the deletion. Skip if the workflow stopped on a failure and the user may resume — keep the folder so a resumed stage can still read it. This is the single deletion for the whole flow; child skills never delete it.
  3. Display the on-device (iPad) validation script and await confirmation. Once the metadata cache is
    Status='Active'
    and the summary is shown, display the script verbatim from
    references/stage-6-ipad-validation-script.md
    (the login uses the Stage-6 KAM user's credentials), then wait for the user to confirm the on-device steps succeeded. Once confirmed, the setup is complete.

  1. 展示完整工作流总结:显示标题"Life Sciences Cloud KAM设置完成",然后按阶段展示实际值:(1) 先决条件已确认;(2) 对象/配置文件/配置记录已部署,KAM与冲刺设置已写入,布局 + Flexipage,28个触发器处理程序;(3) 区域模型
    <model>
    (已激活) + 三级区域
    <territory>
    ;(4) 参与者角色
    Rep Execution Specialist
    + 冲刺
    <name>
    ;(5) 客户 + HCP,产品主数据,关联
    <territory>
    的ProductTerritoryAvailability,2条目标定义,行动计划模板
    <name>
    (最终版) + 3个任务 + 分配,目标 + 模板 + 2个PATI已共享至区域
    <territory>
    ;(6) 用户
    <name>
    <username>
    )使用
    LSC Custom Profile
    ,权限集Health Cloud Starter + Life Sciences Key Account Management + Life Sciences Field Sales Representative + Life Sciences Core,区域
    <territory>
    (管理员 + KAM),移动元数据缓存已生成。结束语:"该组织已就绪,可运行Life Sciences Cloud关键客户管理工作流。"
  2. 清理——删除共享源文件夹一次。在展示最终总结后(所有6个阶段完成),从当前工作目录执行:
    bash
    rm -rf .lsc-starter-config
    此操作静默执行——无需打印清理日志或提及删除操作。若工作流因失败终止且用户可能恢复流程,跳过此步骤——保留文件夹以便恢复阶段可读取。这是整个流程中唯一的删除操作;子Skill绝不会删除该文件夹。
  3. 展示设备端(iPad)验证脚本并等待确认。一旦元数据缓存状态为
    Status='Active'
    且已展示总结,原样展示
    references/stage-6-ipad-validation-script.md
    中的脚本(登录使用阶段6创建的KAM用户凭据),然后等待用户确认设备端步骤已成功完成。确认后,设置流程完成。

State Tracking

状态跟踪

Maintain overall orchestration state:
text
OrchestrationState = {
  targetOrg: string,
  sourceFolderDownloaded: boolean,   // downloaded in Phase 1, deleted in Phase 9
  territoryId?: string, territoryName?: string,   // captured in Stage 3, reused in Stages 5 & 6
  stages: [
    { name: "Prerequisites",       status: "pending|running|passed|failed|skipped" },
    { name: "StarterConfig",       status: "pending|running|passed|failed" },
    { name: "TerritorySetup",      status: "pending|running|passed|failed", territoryId?: string, territoryName?: string },
    { name: "ParticipantSprint",   status: "pending|running|passed|failed", roleId?: string, sprintId?: string },
    { name: "DataAndPlanTemplates",status: "pending|running|passed|failed", accountId?: string, marketableProductId?: string, templateVersionId?: string },
    { name: "UserProvisioning",    status: "pending|running|passed|failed", userId?: string, username?: string }
  ]
}

维护整体编排状态:
text
OrchestrationState = {
  targetOrg: string,
  sourceFolderDownloaded: boolean,   // 第1环节下载,第9环节删除
  territoryId?: string, territoryName?: string,   // 阶段3捕获,阶段5 & 6复用
  stages: [
    { name: "Prerequisites",       status: "pending|running|passed|failed|skipped" },
    { name: "StarterConfig",       status: "pending|running|passed|failed" },
    { name: "TerritorySetup",      status: "pending|running|passed|failed", territoryId?: string, territoryName?: string },
    { name: "ParticipantSprint",   status: "pending|running|passed|failed", roleId?: string, sprintId?: string },
    { name: "DataAndPlanTemplates",status: "pending|running|passed|failed", accountId?: string, marketableProductId?: string, templateVersionId?: string },
    { name: "UserProvisioning",    status: "pending|running|passed|failed", userId?: string, username?: string }
  ]
}

Idempotent Stage Transitions & Mid-Flow Changes

幂等阶段转换与流程中变更

Stages are not re-entrant. Before executing any stage, check its
status
:
running
→ reply "Stage N is already in progress" and take no action;
passed
→ ask explicit confirmation before re-running;
failed
→ re-run (recovery);
pending
→ advance. Set
running
at execution start (not on user input) so accidental double-confirms never run a stage twice.
If the user requests a change to an earlier stage's inputs while a later stage is in progress/pending, run an impact assessment first: acknowledge without applying, identify affected vs. unaffected stages, present options (re-run affected / apply forward only / cancel), and wait for the decision. Surface destructive-change warnings (an activated territory model can't be deleted; an existing user/records/published template remain).
The full behavior matrix, impact-assessment template, per-change impact mapping, and destructive-change warnings are in
references/state-machine-and-changes.md
.

阶段不可重入。在执行任何阶段前,检查其
status
running
→ 回复"阶段N正在执行中"且不执行任何操作;
passed
→ 重新运行前需明确确认;
failed
→ 重新运行(恢复);
pending
→ 推进流程。在执行开始时设置
running
状态(而非用户输入时),避免意外重复确认导致阶段重复运行。
若用户在后续阶段执行中/待执行时请求修改早期阶段的输入,先运行影响评估:确认收到请求但暂不应用,识别受影响和不受影响的阶段,展示选项(重新运行受影响阶段 / 仅向前应用变更 / 取消),等待用户决策。需提示破坏性变更警告(已激活的区域模型无法删除;现有用户/记录/已发布模板会保留)。
完整行为矩阵、影响评估模板、各变更的影响映射和破坏性变更警告详见
references/state-machine-and-changes.md

Rules / Constraints

规则/约束

  • Org: run Phase 0 org selection first; never silently reuse the default org.
  • Shared folder: download
    .lsc-starter-config/LSStarterConfig
    exactly once (Phase 1 hard gate), delete it exactly once (Phase 9); child skills never touch it — Stages 2 and 5 read it, so proceeding without it fails downstream.
  • Order: execute stages strictly 1→6, gating each on prior success; capture each stage's outputs (IDs, names) for later stages.
  • Territory invariant: reuse the SAME Stage-3 level-3 territory (
    OrchestrationState.territoryId
    ) for Stage 5 (ProductTerritoryAvailability) and Stage 6 (user alignment), or the KAM user sees no data.
  • Confirmation: confirm only the fields each stage marks admin-confirmable; auto-derive the rest and show for confirmation.
  • Idempotency: never re-execute a
    running
    /
    passed
    stage without confirmation (set
    running
    at execution start); impact-assess before applying mid-flow changes.

  • 组织:优先执行第0环节的组织选择;切勿默认复用现有组织。
  • 共享文件夹:仅在第1环节下载
    .lsc-starter-config/LSStarterConfig
    一次(硬校验),仅在第9环节删除一次;子Skill绝不会操作该文件夹——阶段2和5会读取它,因此无该文件夹时后续流程会失败。
  • 顺序:严格按1→6的顺序执行阶段,每个阶段依赖前一阶段的成功;捕获每个阶段的输出(ID、名称)供后续阶段使用。
  • 区域一致性:阶段3的三级区域(
    OrchestrationState.territoryId
    )需在阶段5(ProductTerritoryAvailability)和阶段6(用户关联)中复用,否则KAM用户无法查看数据。
  • 确认:仅确认每个阶段标记为需管理员确认的字段;其余字段自动推导并展示供确认。
  • 幂等性:未经确认,不得重新执行
    running
    /
    passed
    状态的阶段(执行开始时设置
    running
    );流程中应用变更前需进行影响评估。

Gotchas

常见问题

IssueResolution
Source download fails in Phase 1Hard stop — do NOT run any stage. Fix the cause or download
.lsc-starter-config/LSStarterConfig
manually into the CWD, then re-run
No connected orgs foundGo straight to the fresh-org login (
sf org login web
) in Phase 0
Artifacts exist from a prior runChild skills/references are idempotent/upsert-safe — query to confirm, then skip or re-run
Stage re-triggered, or earlier input changed mid-flowSee
references/state-machine-and-changes.md

问题解决方案
第1环节源文件夹下载失败终止流程——不得运行任何阶段。修复问题或手动将
.lsc-starter-config/LSStarterConfig
下载至当前工作目录,然后重新运行
未找到已连接组织直接进入第0环节的新组织登录流程(
sf org login web
存在之前运行的遗留产物子Skill/参考文件支持幂等/更新插入——查询确认后,跳过或重新运行
阶段被重新触发,或流程中早期输入被修改详见
references/state-machine-and-changes.md

Resume / Partial Re-run

恢复/部分重新运行

If the user may have already completed some stages, ask which, then verify each claimed-complete stage by querying the org (1 = ask; 2 =
LSC Custom Profile
; 3 = active model + L3 territory; 4 =
ParticipantRole
+
Sprint
; 5 = Account +
ProductTerritoryAvailability
+
Final
version + assignment; 6 =
kam
user + permsets + territory), skip verified stages, and resume from the first incomplete one. Exact per-stage queries:
references/orchestration-flow.md
→ Resume Logic.

若用户可能已完成部分阶段,询问已完成的阶段,然后通过查询组织验证每个声称已完成的阶段(1 = 询问;2 =
LSC Custom Profile
存在;3 = 激活的模型 + 三级区域存在;4 =
ParticipantRole
+
Sprint
存在;5 = Account +
ProductTerritoryAvailability
+
Final
版本 + 分配存在;6 =
kam
用户 + 权限集 + 区域存在),跳过已验证的阶段,从第一个未完成的阶段恢复。各阶段的具体查询语句:
references/orchestration-flow.md
→ 恢复逻辑。

Reference File Index

参考文件索引

FileWhen to read
references/orchestration-flow.md
At start — dependency diagram, gate + resume-detection queries, timing
references/state-machine-and-changes.md
On a re-triggered stage or a mid-flow input change
references/stage-2-starter-config-overview.md
Stage 2 — 13-step deploy + KAM/Sprint config records (points to sibling refs)
references/stage-4-participant-role-and-sprint.md
Stage 4 — participant role + sprint
references/stage-5-data-and-plan-templates-overview.md
Stage 5 — KAM data creation (Part A, points to its data ref) + goals, tasks, measures, action plan template (Part B)
references/stage-6-user-provisioning-overview.md
Stage 6 — user provisioning + metadata cache (points to sibling refs)
references/stage-6-ipad-validation-script.md
Final step — on-device (iPad) validation script shown after the metadata cache is Active
文件读取时机
references/orchestration-flow.md
流程启动时——依赖关系图、校验 + 恢复检测查询、时间规划
references/state-machine-and-changes.md
阶段被重新触发或流程中输入被修改时
references/stage-2-starter-config-overview.md
阶段2时——13步部署 + KAM/冲刺配置记录(指向同级参考文件)
references/stage-4-participant-role-and-sprint.md
阶段4时——参与者角色 + 冲刺创建
references/stage-5-data-and-plan-templates-overview.md
阶段5时——KAM数据创建(A部分,指向其数据参考文件) + 目标、任务、指标、行动计划模板创建(B部分)
references/stage-6-user-provisioning-overview.md
阶段6时——用户配置 + 元数据缓存(指向同级参考文件)
references/stage-6-ipad-validation-script.md
最终步骤时——元数据缓存激活后展示设备端(iPad)验证脚本