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

custom-field-creation

Use when creating a new custom field on any Salesforce object: choosing field type, setting API name, configuring Field-Level Security, adding to page layouts, and deploying. Triggers: 'add a field', 'new custom field', 'what field type should I use', 'FLS not working', 'field not showing on page layout'. NOT for creating the object itself - use admin/object-creation-and-design. NOT for formula field logic - use admin/formula-fields. NOT for picklist value set management - use admin/picklist-and-value-sets. Also covers: field-meta.xml, CustomField metadata, deleteConstraint, externalId, unique, precision and scale, relationshipOrder, writeRequiresMasterRead, fieldPermissions, package.xml for fields.

インストール方法を見る

含まれるファイル(8)

  • SKILL.md22.0 KB
  • references/examples.md8.1 KB
  • references/gotchas.md22.6 KB
  • references/llm-anti-patterns.md9.3 KB
  • references/metadata-examples.md33.8 KB
  • references/well-architected.md7.5 KB
  • scripts/check_custom_field_creation.py16.1 KB
  • templates/custom-field-creation-template.md2.7 KB

SKILL.md(原文)

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

Custom Field Creation

Use this skill when a practitioner needs to add a new custom field to any Salesforce object — from choosing the right field type through FLS configuration, page layout placement, and deployment to production. The skill covers all field types on both standard and custom objects.


Before Starting

Gather this context before working on field creation:

ContextWhat to confirm
Target objectStandard object (Account, Contact, Opportunity, Case, Lead) or custom object?
Data typeWhat kind of data is being stored? Text, number, date, a relationship to another object, a yes/no flag?
CardinalityIs there a fixed set of valid values (use Picklist) or free-form text?
Who needs accessWhich profiles or permission sets need read vs. edit access?
Required?Does every record need this field? If yes, existing records and integrations must be able to provide the value.
Deployment targetIs this going to production? Change set or SFDX/sf CLI?

The most common wrong assumption: creating a field is enough to make it visible to users. It is not. FLS and page layout must also be configured.


Questions to Ask Before Configuring

Ask these before opening the field editor or writing the field-meta.xml. Each one maps to a gotcha in references/gotchas.md; skipping them yields a field that deploys and is still wrong.

AskWhy it mattersWhat a good answer adds
"Who writes this value — a person, a nightly integration, or both?"An integration-owned field almost always needs externalId plus unique; a person-owned one needs inlineHelpText. Non-unique external IDs fail upserts at runtime with HTTP 300The externalId / unique / caseSensitive triple, and whether help text is needed at all
"If the parent record is deleted, what should happen to this one?"deleteConstraint defaults to SetNull, which silently blanks the lookup rather than blocking the deleteAn explicit Cascade / Restrict / SetNull written into the XML
"Does anything need to know what this value used to be?"trackHistory is the only durable record of a change, and it will not deploy unless the object has enableHistoryA trackHistory decision plus the object change in the same deploy
"Is the value one of a closed set, and can the API be allowed to add to it?"An unrestricted picklist lets data loads write values no dashboard groupsrestricted true, or a documented reason to leave it open — and a pointer to admin/picklist-and-value-sets if the set is shared
"Which permission set will grant this field, and is it in the same deploy?"The field and its FLS are separate components; a field shipped without one is invisible. A required field cannot carry FLS metadata at allThe permissionsets/*.permissionset-meta.xml entry, or the decision to leave a required field implicit
"Do we already have a field that holds this?"Field count per object is capped and dead fields are expensive to remove laterEither a reuse decision or a named reason the existing field will not do
"If this is a relationship, which side owns the record?"On a junction, relationshipOrder decides ownership, sharing, and delete behaviour, and reparentableMasterDetail defaults to falseThe primary/secondary assignment and whether children can be moved

What a proper configuration adds over just creating the field: the field arrives with the permission set that exposes it, its delete and uniqueness behaviour is a written decision rather than a platform default, and the type is one you can still live with after the data lands.


Core Concepts

1. Field Type Changes Are Allowed — and That Is the Danger

Most conversions are permitted: Text → Picklist, Number → Currency, and Picklist → Multi-Select Picklist all go through. The risk is not that Salesforce refuses, it is that stored values disappear. Salesforce's rule is to convert only custom fields that hold no data. Conversions documented as data-losing: to or from Date or Date/Time; to Number, Percent, or Currency from any other type; from Checkbox to any other type; to or from Multi-Select Picklist; from Text to Picklist; from Auto Number to any other type except Text; to Auto Number from any type except Text; and from Long Text Area to any type except Email, Phone, Text, Text Area, or URL.

A smaller set is blocked outright: Formula fields convert neither in nor out, Classic Encrypted Text converts neither in nor out, and no custom field referenced in Apex or on a Visualforce page can change type at all. Text ↔ Auto Number is the safe round trip, with Auto Number capped at 30 characters. Plan the type before clicking Save anyway — see references/gotchas.md Gotcha 6 for what a lossy conversion destroys beyond the field itself.

2. Three Separate Access Layers

Salesforce has three independent layers that must all be configured for a user to see and use a custom field:

  1. Field definition — the field exists on the object (created in Object Manager).
  2. Field-Level Security (FLS) — controls which profiles or permission sets can see (Read) or edit (Edit) the field. Newly created fields default to hidden for all profiles in Enterprise and Unlimited editions.
  3. Page layout — controls whether the field appears on the record detail/edit page in the UI. FLS and page layout are independent: a field can be on a layout but hidden by FLS (user sees nothing), or accessible via FLS but not on any layout (accessible via API and reports, but not the UI record page).

All three must be configured. Missing any one of them is why users cannot see a new field.

3. API Name Rules and Permanence

The API name is permanent after save. Rules:

  • Maximum 40 characters
  • Alphanumeric characters and underscores only
  • Must start with a letter
  • Cannot end with an underscore
  • Cannot contain consecutive underscores
  • Salesforce appends __c automatically

Choose a clear, unambiguous name. "Billing_Region__c" is better than "BR__c". You cannot rename an API name after creation.

4. Platform Limits

EditionCustom Fields per Object
Contact Manager, Group100
Essentials100
Professional100
Enterprise500
Performance, Unlimited800
Developer500

Source for both tables: Salesforce Help — Custom Field Allocations and Custom Field Types (listed in references/well-architected.md). UNVERIFIED (2026-09-04): these per-edition and per-type figures are not present in the Summer '26 Salesforce Developer Limits and Allocations quick reference, and help.salesforce.com cannot be fetched here — confirm the ceiling for your org at Setup → Company Information before planning against it.

Key type-level limits:

Field typeLimit
TextMax 255 characters
Text AreaMax 255 characters (multi-line display)
Long Text Area256 to 131,072 characters (configurable)
Rich Text AreaUp to 131,072 characters
NumberMax 18 digits, max 17 decimal places
Classic Encrypted TextMax 175 characters; cannot be used in formulas, reports, or workflow criteria

Field Type Decision Guide

Data NeedRecommended TypeNotes
Short free-form text (name, code, ID)TextMax 255 chars. Can be marked as External ID or Unique.
Multi-line notes or descriptionsLong Text AreaMin 256 chars. Use instead of Text Area for longer content.
Rich text with formattingRich Text AreaStores HTML; max 131,072 chars.
Fixed list of choicesPicklistConsider Global Value Set if values are reused across objects.
Multiple selections from a listMulti-Select PicklistStored as semicolon-delimited string; harder to filter in reports.
Whole numberNumber (0 decimal places)Use Currency for monetary amounts.
Money amountCurrencyRespects org currency settings; supports multi-currency.
Ratio or percentagePercentStored as decimal, displayed with % symbol.
Yes/No boolean flagCheckboxDefaults to unchecked; cannot be set as Required.
Calendar date onlyDateNo time component.
Date and timeDate/TimeStored in UTC; displayed in user's timezone.
Email addressEmailValidates format; renders as email client link.
Phone numberPhoneStores any format; add validation rule for specific format enforcement.
Web addressURLRenders as clickable link; max 255 chars.
Auto-incrementing record numberAuto NumberFormat defined at creation; cannot be changed after.
Relationship to another record (optional parent)Lookup RelationshipParent can be blank; no cascade delete; no roll-up summary.
Required parent relationship with cascade deleteMaster-Detail RelationshipParent required; delete cascades; enables Roll-Up Summary.
Computed read-only valueFormulaNot stored in DB; computed at runtime.
Aggregated value from child recordsRoll-Up SummaryOnly on Master-Detail parent objects; supports Count, Sum, Min, Max.
Geographic coordinatesGeolocationStores latitude and longitude; enables DISTANCE() formula.

Common Patterns

Pattern 1: Build from Scratch — New Field for a Business Requirement

When to use: A stakeholder requests a new data capture point on any object.

Steps:

  1. Navigate to Setup → Object Manager → [Object] → Fields & Relationships → New.
  2. Select field type using the decision guide above. Click Next.
  3. Enter Field Label (user-facing name). Salesforce auto-populates Field Name (API name) — review it. Add Description (internal notes for admins) and Help Text (shown to end users).
  4. Configure type-specific options: Length (Text), Decimal Places (Number/Currency), Visible Lines (Long Text Area), picklist values.
  5. On "Establish Field-Level Security": set Read and/or Edit per profile. Include every profile whose users need access.
  6. On "Add to Page Layouts": select every layout where the field must appear.
  7. Click Save.
  8. Verify: use View as a target user or log in as a test user. Confirm the field is visible and editable.

Pattern 2: Review / Troubleshoot — Field Not Visible to Users

When to use: A user reports they cannot see a field that was recently created.

Diagnosis steps:

  1. Setup → Object Manager → [Object] → Fields & Relationships → [Field] → Set Field-Level Security. Confirm the user's profile (or relevant permission set) has at least Read access checked.
  2. Setup → Object Manager → [Object] → Page Layouts → [Applicable layout]. Confirm the field appears on the layout canvas (not just in the palette on the left, which means it is NOT on the layout).
  3. If the org uses Lightning Record Pages with Dynamic Forms: Setup → App Builder → [Record page for this object] → check the Dynamic Form component. In Dynamic Forms, fields must be added to the form component individually — the page layout is not used for those fields.
  4. Check the user's active record type and which layout is assigned to that record type for that profile.

Pattern 3: Lookup vs. Master-Detail — Choosing the Right Relationship Type

Lookup Relationship — use when:

  • The parent record is optional (child can exist without a parent)
  • Deleting the parent should NOT delete child records
  • Child records have their own ownership and sharing rules
  • Roll-up summaries are not needed

Master-Detail Relationship — use when:

  • Every child record must have a parent (field is always required)
  • Deleting the parent should cascade-delete all children
  • Roll-Up Summary fields are needed on the parent
  • Child records should inherit the parent's sharing model

A Lookup can be converted to Master-Detail later only if no child records have a blank parent. Master-Detail cannot be converted to Lookup if the object has Roll-Up Summary fields using that relationship.


Recommended Workflow

  1. Answer the seven questions above and fill in templates/custom-field-creation-template.md. The answers decide type, required, unique, deleteConstraint, restricted, and which permission set ships with the field. Stop here if the answer to "do we already have a field that holds this?" is yes.
  2. Pick the type from the enum, not from the UI label. references/metadata-examples.md lists every valid FieldType value and the four spellings LLMs get wrong (MasterDetail, Url, Location, Summary).
  3. Write the .field-meta.xml at objects/<Object>/fields/<Name>__c.field-meta.xml, copying the closest of the eight worked examples in references/metadata-examples.md (§1 required text, §2 external ID, §3 number, §4 checkbox and date, §5 lookup with filter, §6 junction master-detail, §7 restricted picklist, §8 data classification).
  4. Write the fieldPermissions entry in the same change — references/metadata-examples.md §9. Omit it only for required fields, which cannot carry FLS metadata. Add the Layout (or Dynamic Form) change to the same manifest.
  5. Build the package.xml by enumerating each Object.Field__c (§10). CustomField accepts no wildcard; a * manifest ships nothing and does not error.
  6. Run the checker over the source tree before deploying: python3 scripts/check_custom_field_creation.py --manifest-dir force-app/main/default. Resolve every WARN or justify it in the template's Notes section.
  7. Validate, deploy, verify — sf project deploy start --dry-run first, then deploy, then confirm the shape the org actually has with the sf sobject describe, FieldPermissions SOQL, and Schema.DescribeFieldResult checks in references/metadata-examples.md §11–§12. Log in as a target user; a clean deploy is not evidence anyone can see the field.

Review Checklist

Before marking field creation complete:

  • Field type chosen intentionally — most conversions are allowed later, but the data-losing ones destroy stored values, and where data is lost every list view built on the field is deleted.
  • API name reviewed: clear, unique, under 40 characters, no trailing underscores.
  • Description and Help Text filled in — helps future admins and end users.
  • FLS configured for all profiles or permission sets that need Read and/or Edit access.
  • Field added to all relevant page layouts for the target user group.
  • If Dynamic Forms are in use on any Lightning record page, field added to the Dynamic Form component.
  • Required setting validated: if required, existing records and integrations can provide the value.
  • Tested as a target user (View as user or dedicated test user in sandbox).
  • Deployment artifact prepared: field + page layout(s) included in change set or SFDX retrieve manifest.
  • Production deployment validated: field visible and editable for users in production.

Salesforce-Specific Gotchas

  1. New fields are hidden for all profiles in Enterprise/Unlimited editions — When you create a field in Enterprise or Unlimited, the default FLS is hidden (no access) for all profiles. If you click through the FLS screen without setting visibility, no user (other than System Administrators in some editions) can see the field. The field exists and stores data written via API, but the UI and reports show it as blank or invisible.

  2. Required fields break existing records and integrations — Marking a field Required at the field definition level causes the Salesforce API to reject any DML (from UI, triggers, or integrations) that does not supply the field. If you convert an optional field to required after records already exist without values, bulk operations and integrations that do not explicitly set the field will start producing errors. Provide a default value or run a data update before making an existing field required.

  3. Dynamic Forms bypass classic page layouts for field display — If a Lightning record page uses the Dynamic Forms feature in Lightning App Builder, fields on the classic page layout are NOT automatically shown. Dynamic Forms replaces the classic layout's field section with a custom field component. Adding a field to the classic page layout has no effect for users seeing the Dynamic Forms version of the page. The field must be added directly to the Dynamic Form component in App Builder.


Output Artifacts

ArtifactDescription
Field type recommendationWhich type to use and why, based on business requirement
Creation and configuration checklistStep-by-step including FLS, layout, and Dynamic Forms
Deployment manifest noteWhich metadata types to include: CustomField, Layout, PermissionSet (if FLS via perm sets)

Reference Files

FileRead it when
references/metadata-examples.mdWriting the .field-meta.xml for any field type, the fieldPermissions entry, the package.xml, the retrieve/deploy commands, or the post-deploy describe and FLS verification
references/gotchas.mdFourteen platform behaviours that make a field wrong after it deploys — FLS retrieve rewrites, deleteConstraint defaults, non-unique external IDs, junction ownership, wildcard-free manifests, precision arithmetic
references/examples.mdLooking for a worked scenario end to end: picklist over text, date over text, master-detail over lookup, and the text-instead-of-picklist anti-pattern
references/llm-anti-patterns.mdReviewing a field an assistant generated, before it reaches a deploy
references/well-architected.mdFraming the design against Security, Operational Excellence, and Scalability, and for the full source list
templates/custom-field-creation-template.mdDocumenting any field worth reviewing — field summary, type rationale, FLS matrix, layout placement, deployment checklist

Related Skills

  • admin/formula-fields: Use when the value should be computed from other fields at read time rather than stored. Also owns the formula / formulaTreatBlanksAs XML.
  • admin/picklist-and-value-sets: Use when managing picklist values, global value sets, restriction, or value deactivation. NOT for the picklist field's own definition, which is here.
  • admin/field-dependency-and-controlling: Use when one picklist filters another; controllingField and valueSettings are designed there.
  • admin/lookup-and-relationship-design: Use to choose between Lookup, Master-Detail, and a junction object before writing either relationship field.
  • admin/lookup-filter-cross-object-patterns: Use when the requirement is to constrain which parent records a lookup offers, beyond the single filter shown here.
  • admin/compound-field-patterns: Use for Address, Geolocation, and Name compound fields, whose component fields behave differently from ordinary custom fields.
  • admin/system-field-behavior-and-audit: Use for field history retention, trackHistory querying, and system audit fields.
  • admin/permission-set-architecture: Use when designing which permission sets exist and how FLS is grouped across users; this skill only ships the one fieldPermissions entry.
  • admin/object-creation-and-design: Use when deciding whether a new custom object beats adding fields to an existing one.

レビュー

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

同じリポジトリのスキル

概要と使いどころ

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

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