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

record-type-id-management

RecordType ID differences across orgs: dynamic lookup via Schema.SObjectType methods, DeveloperName for stable refs, hard-coded ID anti-patterns, record-type caching, deployment impact. NOT for deciding whether to use record types at all — use admin/record-types-and-page-layouts. NOT for layout/profile explosion at scale — use admin/record-type-strategy-at-scale. NOT for hard-coded Profile, Queue or User IDs in Apex — use apex/apex-hardcoded-id-elimination.

インストール方法を見る

含まれるファイル(7)

  • SKILL.md6.9 KB
  • references/examples.md6.1 KB
  • references/gotchas.md5.9 KB
  • references/llm-anti-patterns.md3.1 KB
  • references/well-architected.md5.1 KB
  • scripts/check_record_type_id_management.py4.3 KB
  • templates/record-type-id-management-template.md637 B

SKILL.md(原文)

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

Record Type ID Management

Activate when code, flow, or configuration references record types by ID. Record type IDs are org-specific and change across sandbox refreshes, packaging, and org clones. Hard-coded IDs are one of the most common causes of "works in sandbox, fails in production" deployment failures on Salesforce.

Before Starting

  • Grep the codebase for IDs that look like record-type keys. Apex string literals starting with 012 are the smoking gun.
  • Prefer DeveloperName over Name. Admins rename labels; DeveloperName is the stable API handle.
  • Know the caching story. Schema.SObjectType.RecordTypeInfosByDeveloperName is cached per transaction — safe to call often, but not free across transactions.

Core Concepts

DeveloperName is the stable handle

Record types have three identifiers: Id (org-specific), Name (user-facing label), DeveloperName (API name). Only DeveloperName is stable across orgs. All code and config should reference by DeveloperName, resolving to Id at runtime.

Schema.SObjectType resolution

Apex: Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Business_Account').getRecordTypeId(). Returns the Id in the current org. Works everywhere — triggers, batch, LWC @AuraEnabled methods.

Flow

Flow formula or Get Records on RecordType with SobjectType and DeveloperName filters. Avoid referencing record-type Ids directly in flow; use the record type lookup component or DeveloperName-based query.

Validation rules and formulas

Formulas can reference $RecordType.DeveloperName (scoped to the context record). Compare to strings rather than IDs. RecordType.DeveloperName = 'Business_Account' survives deployment; RecordTypeId = "012..." does not.

LWC

LWC receives record-type Id via @wire(getObjectInfo) which returns recordTypeInfos keyed by Id with name and developerName attributes. Resolve DeveloperName → Id on the client once per session.

Common Patterns

Pattern: Central Apex utility for record-type resolution

public class RecordTypes {
    public static Id idFor(SObjectType type, String developerName) {
        return type.getDescribe().getRecordTypeInfosByDeveloperName()
                   .get(developerName).getRecordTypeId();
    }
}

Use as RecordTypes.idFor(Account.SObjectType, 'Business_Account'). Cached by the platform; cheap to call repeatedly.

Pattern: Custom Metadata Type as record-type registry

RecordTypeRef__mdt with Object__c, DeveloperName__c, and any semantic flags. Apex/Flow read the CMDT, then resolve to Id. Useful when the same logical "primary" record type differs across products.

Pattern: Validation rule via DeveloperName

AND($RecordType.DeveloperName = 'Business_Account', ISBLANK(Industry)). No ID in the formula. Deploys cleanly to every org.

Decision Guidance

Reference pointPreferred pattern
Apex logicSchema.getRecordTypeInfosByDeveloperName
Flow decisionDeveloperName via Get Records
Validation rule$RecordType.DeveloperName
Formula field$RecordType.DeveloperName
LWC@wire(getObjectInfo) → lookup by developerName
Assignment rule / Approval processRecord-type aware criteria on DeveloperName if possible

Recommended Workflow

  1. Grep codebase for 012[A-Za-z0-9]{12,15} literals and audit every match.
  2. Catalog every record type per object with SELECT DeveloperName, SObjectType FROM RecordType.
  3. Replace each hard-coded Id with the DeveloperName resolution pattern matching its reference point.
  4. Introduce a central RecordTypes utility and migrate Apex references.
  5. Update validation rules and formulas to $RecordType.DeveloperName.
  6. Run a sandbox-refresh smoke test: deploy to a freshly refreshed sandbox and verify no test failures reference ID literals.
  7. Add a CI check that blocks commits containing 18-char record-type IDs.

Review Checklist

  • No hard-coded record-type IDs remain in Apex, LWC, Flow, or metadata
  • Central Apex utility used for ID resolution
  • Validation rules and formulas use $RecordType.DeveloperName
  • LWC resolves via getObjectInfo
  • Smoke test on freshly refreshed sandbox passes
  • CI check blocks new hard-coded record-type IDs
  • Documentation notes DeveloperName convention for admins

Salesforce-Specific Gotchas

  1. Master record type has DeveloperName Master — handle gracefully when looking up the master programmatically.
  2. Inactive record types are not excluded by getRecordTypeInfosByDeveloperName. Filter on isActive() if you care.
  3. Change Sets preserve DeveloperName but not Id. The destination org creates a new Id — code that hard-codes Id from the source fails on first run.

Output Artifacts

ArtifactDescription
Hard-coded ID auditList of files + line numbers with IDs
Central resolver utilityApex class with caching
CI checkRegex hook blocking new ID literals
DeveloperName catalogObject × DeveloperName × purpose

Related Skills

  • apex/apex-mocking-and-stubs — mocking Schema.describe in tests
  • data/data-model-design-patterns — record-type strategy itself
  • devops/salesforce-code-analyzer — CI static-analysis gate

レビュー

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

同じリポジトリのスキル

概要と使いどころ

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 のスキルをすべて見る

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