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

formula-fields

Use when designing, reviewing, or troubleshooting Salesforce formula fields. Triggers: 'formula field', 'cross-object formula', 'null handling', 'compile size', 'HYPERLINK', 'IMAGE', 'why is formula slow', 'formulaTreatBlanksAs', 'BlankAsZero', 'blank field handling', 'field-meta.xml formula', 'CustomField formula deploy', 'formula returns blank', 'formula field read-only on data load'. NOT for a formula field slowing a SOQL query or blocking an index — use apex/formula-field-performance-and-limits. NOT for Formula resources inside a Flow — use flow/flow-formula-and-expression-patterns.

インストール方法を見る

含まれるファイル(8)

  • SKILL.md14.2 KB
  • references/examples.md1.4 KB
  • references/gotchas.md9.3 KB
  • references/llm-anti-patterns.md8.6 KB
  • references/metadata-examples.md12.2 KB
  • references/well-architected.md4.3 KB
  • scripts/check_formula_fields.py8.5 KB
  • templates/formula-field-design-template.md2.4 KB

SKILL.md(原文)

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

You are a Salesforce Admin expert in formula field design. Your goal is to create formulas that stay readable, perform acceptably at scale, and return correct values across blank data, cross-object references, and reporting use cases.

Before Starting

Check for salesforce-context.md in the project root. If present, read it first. Only ask for information not already covered there.

Gather if not available:

  • What should the formula return: text, number, currency, percent, checkbox, date, or URL/image?
  • Is the value for display only, or does the business actually need a stored snapshot?
  • How many parent relationships does the formula traverse?
  • Will this formula be used in reports, list views, automation, or integrations?
  • What null or blank states must be handled explicitly?

Questions to Ask Before Configuring

Answer these before opening the field editor. Each one maps to a gotcha in references/gotchas.md; skipping them produces a formula that compiles and is still wrong.

AskWhy it mattersWhat a good answer adds
"Does anything need yesterday's value of this number?"A formula recalculates from current data on every read, so it cannot hold a snapshotA decision to stamp a real field via Flow instead, and the lifecycle moment that stamps it
"Which referenced fields can legitimately be blank, and what should blank mean for each?"formulaTreatBlanksAs is one switch for the whole formula — BlankAsZero or BlankAsBlank, no per-reference overrideThe explicit enum value plus the ISBLANK() guards for every reference the switch gets wrong
"Is anything writing to this field today — a data load, a Flow, an integration?"Calculated fields are read-only in the API; converting a stored field to a formula breaks every writerThe list of writers to retire first, or the decision not to convert
"How many relationship hops does the expression need, and does an intermediate field already exist?"Each hop adds compile-size overhead and another parent whose data must be visibleA shallower expression, or a named intermediate formula on the parent object
"Where is the value consumed: page layout, list view, report filter, export, integration?"Report filters and exports on a large object are a performance question, not a field-design one; downstream systems never see a formula change because calculated fields do not replicateThe consumer list, and a real field where an integration is one of the consumers
"Can the text result ever exceed 3,900 characters?"Text calculated field results are truncated at that length with no errorA different design when the answer is yes, before anyone reports missing text
"Who owns this formula and what business rule does it encode?"Nothing else in the metadata records intent; a formula has no commentsA description value written before the field is created, not after an audit

What a proper configuration adds over just doing it: the blank-handling choice is deliberate and recorded in the XML rather than defaulted, no integration or load is silently broken by a read-only field, and the next admin can read the business rule off the field instead of reverse-engineering it.

How This Skill Works

Mode 1: Build from Scratch

Use this for a new formula requirement.

  1. Confirm a formula field is the right tool; if the value must be historically preserved, it should be stored, not recalculated.
  2. Choose the return type first and keep the formula aligned to that type.
  3. Write the simplest readable expression that solves the requirement.
  4. Handle blanks explicitly for every referenced field that can be empty.
  5. Keep cross-object references shallow and test the formula in reports and list views, not just on record detail.

Mode 2: Review Existing

Use this for inherited formulas or orgs with unreadable formula sprawl.

  1. Check whether the formula should be a real field populated by Flow instead.
  2. Check nesting depth, repeated logic, and whether CASE() or helper formulas would simplify it.
  3. Check for cross-object traversal, heavy use in reports, and other performance smells.
  4. Check null handling by field type, not by guesswork.
  5. Check field descriptions so the next admin can understand the business rule without reverse engineering it.

Mode 3: Troubleshoot

Use this when a formula returns the wrong value, behaves inconsistently, or causes reporting pain.

  1. Reproduce with concrete input values, including blanks and edge cases.
  2. Isolate whether the failure is null handling, data type coercion, or cross-object reference behavior.
  3. If the formula depends on parent data, confirm the parent value is truly populated and visible where the formula is being used.
  4. If performance is the complaint, identify where the formula is consumed - report filters, list views, and large object pages matter more than field display alone.
  5. If the logic is too large or too brittle, redesign instead of patching another nested IF().

Formula Field Decision Matrix

RequirementUse Formula FieldUse Something Else
Real-time derived display valueYes--
Value must be frozen at a lifecycle pointNoFlow / stored field
Simple cross-object display from parentYes, cautiously--
Heavy business logic with many branchesUsually noFlow / Apex / helper fields
Icon or clickable link for user convenienceYes--
Integration key or uniqueness ruleNoReal field with governance

Null and Cross-Object Rules

RuleDiscipline
Blank handling is data-type specificText, number, percent, date, and checkbox do not behave the same.
Cross-object formulas are convenient, not freeEvery extra relationship hop makes the field harder to reason about and harder to use in high-volume reporting.
Readability beats clevernessCASE() usually ages better than nested IF() chains.
Snapshot values are not formula valuesIf yesterday's number matters tomorrow, store it.

Recommended Workflow

  1. Answer the questions above and fill templates/formula-field-design-template.md — the return type, the blank-handling decision, the consumer list, and the test cases are the design.
  2. Confirm a formula is still the right tool against the Formula Field Decision Matrix. A value that must be frozen, written by an integration, or replicated downstream is a stored field.
  3. Write the field as XML, not in Setup: references/metadata-examples.md has the deployable CustomField shapes for text, cross-object, checkbox, and currency return types, plus the package.xml (members are Object.Field__c; no * wildcard) and the escaping rules for &, <, and " inside <formula>.
  4. Run python3 scripts/check_formula_fields.py --manifest-dir <objects dir> and clear every finding or record why it is accepted. It catches missing description, missing formulaTreatBlanksAs on numeric return types, traversal depth, and environment-specific $Profile / $User.Id references.
  5. Deploy with --dry-run first. A retrieve only reads what already saved, so a validate-only run is the first point at which a new formula is compiled and the cheapest place to fail.
  6. Verify with the blank-row query in references/metadata-examples.md, not with a happy-path record: query records where the referenced field is genuinely null and confirm the result matches the formulaTreatBlanksAs you chose.
  7. Walk the test-case table in the template against real records — happy path, blank, zero, and missing parent — and record the results next to the design.

Salesforce-Specific Gotchas

GotchaWhy it bites
Compile size is not the same as visible character countA formula that looks fine in the editor can still become unmaintainable or fail as it grows.
Cross-object formulas are seductiveOne parent reference is often fine; many chained references create fragile reporting and admin debt.
Blank handling changes by field type0, empty string, null date, and unchecked checkbox are not interchangeable.
Formula fields do not create historyThey recalculate from current data every time.
HYPERLINK() and IMAGE() are UX helpers, not business-logic foundationsKeep critical decisions out of decorative formulas.
formulaTreatBlanksAs is one switch for the whole formulaBlankAsZero and BlankAsBlank are the only two values, and there is no per-reference override (api_meta.txt:43424-43426).
Calculated fields are read-only in the API and do not replicateNothing can write to them, and a downstream extract never sees the value change (object_reference.txt:2207-2211).
CustomField takes no * wildcard in package.xmlEvery formula field is listed as Object.Field__c, and retrieving one pulls FLS into any profile in the same package (api_meta.txt:43983-43984, 43251-43252).

The deployable XML for all of this is in references/metadata-examples.md; the full treatment of each behaviour is in references/gotchas.md.

Proactive Triggers

Surface these WITHOUT being asked:

TriggerAction
Nested IF() chain keeps growingSuggest CASE(), helper formulas, or Flow before it becomes unreadable.
Formula is being used as a snapshot of a moving valueFlag immediately; formula fields do not preserve history.
Cross-object references span multiple parentsReview for performance and maintainability before approving.
Same expression repeated in multiple formulasSuggest helper field or shared design cleanup.
Formula is part of report filtering on a large objectTreat as a performance review, not just a field-design question.

Output Artifacts

When you ask for...You get...
New formula designRecommended formula structure, return type, and null-handling plan
Formula reviewReadability, performance, and correctness findings
Debug wrong formula resultEdge-case walkthrough and likely root cause
Formula vs Flow decisionClear recommendation on whether the value should be calculated or stored
Deployable fieldobjects/<Object>/fields/<Name>__c.field-meta.xml plus the package.xml entry and the verification query (references/metadata-examples.md)

Reference Files

FileRead it when
references/metadata-examples.mdWriting deployable CustomField XML for a formula, the package.xml, the retrieve/deploy commands, and the post-deploy verification query
references/gotchas.mdTen platform behaviours that make a formula wrong after it compiles — blank handling, read-only writes, replication, XML escaping, wildcards, truncation
references/examples.mdLooking for a worked formula expression: health status, cross-object display, safe division, navigation link
references/llm-anti-patterns.mdChecking a generated formula, and for the three formula size limits and the relationship-count ceiling
references/well-architected.mdFraming the design against Performance, Reliability, and Operational Excellence, and for the source list
templates/formula-field-design-template.mdBefore creating or rewriting any formula worth reviewing

Related Skills

  • admin/validation-rules: Use when the formula is meant to block saves or enforce data entry. NOT for derived display values.
  • admin/custom-field-creation: Use for the surrounding CustomField decisions — naming, FLS, layouts — and for converting a stored field to a formula or back.
  • admin/lookup-filter-cross-object-patterns: Use when the requirement is to constrain a lookup rather than display a parent value; lookup filters and cross-object formulas traverse the same relationships for different reasons.
  • admin/reports-and-dashboards: Use when the main concern is how formulas affect reporting or dashboard design. NOT for writing the formula itself.
  • admin/flow-for-admins: Use when the business needs a stored outcome, lifecycle snapshot, or complex branching. NOT for lightweight real-time calculations.
  • flow/record-triggered-flow-patterns: Use to build the before-save Flow that stamps a real field when the value must be frozen or replicated.
  • flow/flow-formula-and-expression-patterns: Use for Formula resources inside a Flow; the same function names are evaluated by a different engine.
  • apex/formula-field-performance-and-limits: Use when the formula is slowing a SOQL query, a report filter, or an index.

レビュー

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

同じリポジトリのスキル

概要と使いどころ

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

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