本文へ移動
cccskills
無料GitHub で公開

lookup-and-relationship-design

Designing Lookup vs Master-Detail vs Hierarchical vs External relationships: cascade delete, roll-up summaries, ownership, sharing implications, polymorphic lookups, junction objects, relationship depth limits. NOT for restricting which records a lookup can pick — use admin/lookup-filter-cross-object-patterns. NOT for a roll-up across a plain lookup — use data/roll-up-summary-alternatives.

インストール方法を見る

含まれるファイル(7)

  • SKILL.md7.0 KB
  • references/examples.md5.3 KB
  • references/gotchas.md6.4 KB
  • references/llm-anti-patterns.md4.4 KB
  • references/well-architected.md5.5 KB
  • scripts/check_lookup_and_relationship_design.py3.2 KB
  • templates/lookup-and-relationship-design-template.md647 B

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Lookup and Relationship Design

Activate when designing a new parent-child relationship or reviewing an existing data model for correctness. The choice between Lookup, Master-Detail, Hierarchical, and External relationships has lasting implications for sharing, reporting, deletion cascades, and migration complexity — getting it wrong often requires costly rework.

Before Starting

  • Clarify ownership semantics. Does the child have its own owner, or does it inherit from parent? Master-detail forces inheritance; lookup allows independence.
  • Clarify deletion semantics. Should deleting the parent delete the children? Master-detail: yes (cascade). Lookup: configurable (clear field or restrict or cascade).
  • Inventory roll-up aggregates. Roll-up summary fields require master-detail (or use declarative Rollup on lookup via specific features/apps).
  • Count relationship fields per object. Hard limit of 40 relationship fields; soft reporting limits lower.

Core Concepts

Master-Detail

Child record is owned by parent: inherits sharing, cascade-deletes, allows roll-up summary fields on parent. A child cannot exist without a parent. Converting master-detail → lookup is possible only when no orphans exist and no roll-ups reference the field. Max 2 master-detail relationships per object.

When an object carries two (the junction-object shape), the two parents are not interchangeable: one is primary and one is secondary, recorded in the field's Metadata API relationshipOrder (0 = primary, 1 = secondary; always 0 on a non-junction master-detail). The CustomField reference states that designation "affects delete behavior and inheritance of look and feel, and record ownership for junction objects" — a design decision, not a cosmetic one. Settle which parent should govern the junction's ownership and deletion, and set relationshipOrder deliberately.

Lookup

Independent child record; keeps its own owner and sharing. Deletion behavior configurable: "Clear the value of this field" (default), "Don't allow deletion of the parent if a child exists" (restrict), or "Delete this record also" (cascade — requires specific config). No native roll-up summary.

Hierarchical (User object only)

Self-referencing lookup on User for manager hierarchy. Drives CustomField__c sharing and "Role" reporting, but not role hierarchy — that's a separate concept.

External relationships

External Lookup (ExternalLookup), Indirect Lookup (IndirectLookup) — connect to External Objects via Salesforce Connect. Different SOQL semantics and no roll-ups.

Polymorphic lookups

Task.WhatId and Task.WhoId reference multiple object types. SOQL requires TYPEOF or WhatId.Type filters. Only supported on select standard objects.

Common Patterns

Pattern: Master-detail for true parent-child

Opportunity → OpportunityLineItem: cascading delete and roll-up of revenue. Classic.

Pattern: Lookup + restrict delete for loose coupling

Account → Asset: each has its own owner, but deleting an Account with open Assets should be blocked. Configure "Don't allow deletion of the parent."

Pattern: Lookup + Apex roll-up for aggregation

When master-detail is not viable, use a trigger-framework-based rollup (e.g., Declarative Lookup Rollup Summaries app, or custom Apex).

Decision Guidance

NeedRelationship
Cascade delete + roll-up summaryMaster-Detail
Child has independent owner/sharingLookup
User manager hierarchyHierarchical
Child in external systemExternal Lookup
Two possible parent object typesPolymorphic (if supported) or two lookups with validation

Recommended Workflow

  1. Clarify the business semantics: ownership, deletion, aggregation.
  2. Count existing relationship fields on the child object (max 40).
  3. Pick the type from the decision table.
  4. For master-detail, verify data quality: no orphans will exist post-deployment.
  5. Plan the roll-up summary fields (or Apex rollup) if aggregation required.
  6. Document sharing impact — master-detail children inherit from parent.
  7. Add relationship to the data model diagram; review with architect.

Review Checklist

  • Ownership semantics documented and match chosen type
  • Deletion behavior explicit (cascade / restrict / clear)
  • Relationship field count under 40 on child object
  • Roll-up summaries planned where needed
  • Sharing impact analyzed (especially for master-detail)
  • On an object with two master-details, relationshipOrder names the intended parent as primary
  • SOQL path depth under 5 levels for queries traversing this relationship
  • Data model diagram updated

Salesforce-Specific Gotchas

  1. Master-detail creates ownership inheritance. Custom sharing rules on child objects with master-detail are limited; sharing follows parent.
  2. Converting lookup → master-detail requires all rows have a value. Orphans block conversion; cleanup comes first.
  3. SOQL relationship queries cap at 5 levels. Deep hierarchies require multiple queries or flattened references.

Output Artifacts

ArtifactDescription
Relationship design docType choice, rationale, sharing impact
Roll-up aggregation planField list + declarative or Apex approach
Data model diagramParent-child graph with relationship types

Related Skills

  • data/data-model-design-patterns — holistic data model strategy
  • admin/many-to-many-relationships — junction objects
  • apex/apex-rollup-patterns — Apex-based rollups when master-detail unavailable

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Use this skill when writing test-first, behavior-driven acceptance criteria in Given/When/Then format for a Salesforce user story. Covers happy path, edge cases, negative paths, permission boundaries, and data-state preconditions so the AC block can drive UAT scripts and Apex test design downstream. Trigger keywords: given when then, gherkin, behavior driven AC, test first acceptance criteria, scenario outline, BDD acceptance criteria. NOT for the user-story format itself (use admin/user-story-writing-for-salesforce). NOT for UAT script writing (use admin/uat-test-case-design). NOT for Apex test method generation (use agents/test-class-generator). NOT for high-level UAT planning (use admin/uat-and-acceptance-criteria). More triggers: acceptance criteria record, ac_id, req_id on a criterion, artefact under test, negative case for a rule-type requirement, no-match fall-through criterion, oracle for a Then clause, test type apex flow manual, criteria linter, check_ac_format.py, --manifest-dir.

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

Task and Event objects: polymorphic WhatId/WhoId, Activity object model, ActivityHistory vs OpenActivity, activity timeline customization, bulk task creation, Einstein Activity Capture boundaries. NOT for turning on EAC or calendar sync — use admin/einstein-activity-capture-setup. NOT for Email-to-Case — use admin/case-management-setup. Covers ActivitiesSettings metadata, enableActivities, shared Task/Event custom fields and FLS, TaskStatus value sets, Shared Activities and TaskRelation/EventRelation, recurring and child activities, and partial-success bulk DML on Task.

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

Design Invocable Apex actions that return deterministic, agent-friendly errors instead of surfacing raw exceptions to the LLM. NOT for authoring the action itself — @InvocableMethod schema, labels, security context — use agentforce/custom-agent-actions-apex. NOT for the Apex tests that force each error branch — use agentforce/agent-action-unit-tests.

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

Use when designing how an Agentforce agent extracts structured input parameters (slots) from a user's natural-language utterance to invoke an action. Triggers: 'agent extract date from user', 'agent action argument extraction', 'agentforce slot filling', 'agent invocable input mapping', 'agent fails to fill required parameter'. NOT for action authoring (use agentforce/agent-actions) or for prompt-template variable binding (use agentforce/prompt-builder-templates).

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

Apex test patterns for @InvocableMethod agent actions: per-reason-code branch coverage, bulk safety, callout mocking, deterministic assertions. NOT for testing whether the agent routes to the right topic or answers well — use agentforce/agent-testing-and-evaluation. NOT for designing the error envelope the tests assert on — use agentforce/agent-action-error-handling.

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

Designing or reviewing Agentforce actions: Flow actions, Apex invocable actions, prompt-template actions, action naming, input and output contracts, confirmation requirements, and safe error behavior. Triggers: 'agent actions', 'build an agent that can look up an order', 'make the agent able to check order status', 'give the agent a capability', 'agent that can retrieve a record', 'flow action for agent', 'agent invocable action', 'action schema design'. NOT for writing the Apex class itself — use agentforce/custom-agent-actions-apex. NOT for the reason_code error envelope that stops an agent retry loop — use agentforce/agent-action-error-handling.

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

PranavNagrecha のスキルをすべて見る

このスキルの問題を報告する