sf-schema について
Salesforce の開発者やメタデータ担当者向けのスキーマ設計スキルです。オブジェクト、項目、ルール、権限の SFDX ソース形式メタデータの作成を案内し、リレーションの制約やデプロイ時の注意点も扱います。
主な機能
- 01カスタムオブジェクトメタデータの生成
- 02項目と入力規則の定義
- 03権限とレコードタイプの設定
- 04リレーションの制約の説明
- 05SFDX デプロイ手順の提示
活用シーン
- 01オブジェクトと項目の作成
- 02新しいスキーマへの権限設定
- 03リレーションと数式の制約確認
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ clientell-ai/ salesforce-skills --skill sf-schemaインストール後、Claude Code で/sf-schemaを入力して読み込まれたか確認します。
同梱ファイルreferences/schema-reference.md
詳細
スキーマ設計と権限管理
Salesforce のスキーマとメタデータの専門家として、有効な SFDX ソース形式のメタデータを生成します。
カスタムオブジェクト
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Invoice</label>
<pluralLabel>Invoices</pluralLabel>
<nameField>
<label>Invoice Number</label>
<type>AutoNumber</type>
<displayFormat>INV-{000000}</displayFormat>
</nameField>
<deploymentStatus>Deployed</deploymentStatus>
<sharingModel>Private</sharingModel>
<enableActivities>true</enableActivities>
<enableHistory>true</enableHistory>
<enableReports>true</enableReports>
</CustomObject>
カスタム項目
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Amount__c</fullName>
<label>Amount</label>
<type>Currency</type>
<precision>18</precision>
<scale>2</scale>
<required>true</required>
</CustomField>
一般的な項目タイプ
<type>Text</type>
<length>255</length>
<type>LongTextArea</type>
<length>32768</length>
<visibleLines>5</visibleLines>
<type>Picklist</type>
<valueSet>
<restricted>true</restricted>
<valueSetDefinition>
<sorted>false</sorted>
<value><fullName>Active</fullName><default>true</default><label>Active</label></value>
<value><fullName>Inactive</fullName><default>false</default><label>Inactive</label></value>
</valueSetDefinition>
</valueSet>
<type>Lookup</type>
<referenceTo>Account</referenceTo>
<relationshipLabel>Invoices</relationshipLabel>
<relationshipName>Invoices</relationshipName>
<type>MasterDetail</type>
<referenceTo>Account</referenceTo>
<relationshipLabel>Invoices</relationshipLabel>
<relationshipName>Invoices</relationshipName>
<reparentableMasterDetail>false</reparentableMasterDetail>
<writeRequiresMasterRead>false</writeRequiresMasterRead>
<type>Checkbox</type>
<defaultValue>false</defaultValue>
<type>Date</type>
<type>DateTime</type>
<type>Number</type>
<precision>18</precision>
<scale>0</scale>
<type>Text</type>
<formula>Account__r.Name & ' - ' & TEXT(Amount__c)</formula>
入力規則
<?xml version="1.0" encoding="UTF-8"?>
<ValidationRule xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Amount_Must_Be_Positive</fullName>
<active>true</active>
<errorConditionFormula>Amount__c <= 0</errorConditionFormula>
<errorDisplayField>Amount__c</errorDisplayField>
<errorMessage>Amount must be greater than zero.</errorMessage>
</ValidationRule>
権限セット
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Invoice Manager</label>
<hasActivationRequired>false</hasActivationRequired>
<objectPermissions>
<object>Invoice__c</object>
<allowCreate>true</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>true</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<viewAllRecords>true</viewAllRecords>
</objectPermissions>
<fieldPermissions>
<field>Invoice__c.Amount__c</field>
<editable>true</editable>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<field>Invoice__c.Status__c</field>
<editable>true</editable>
<readable>true</readable>
</fieldPermissions>
</PermissionSet>
カスタム権限(フローのバイパス用)
<?xml version="1.0" encoding="UTF-8"?>
<CustomPermission xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Bypass Automation</label>
<isLicensed>false</isLicensed>
</CustomPermission>
その他の項目タイプ
数式項目:
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>FullName__c</fullName>
<label>Full Name</label>
<type>Text</type>
<formula>FirstName__c & ' ' & LastName__c</formula>
<formulaTreatBlanksAs>BlankAsZero</formulaTreatBlanksAs>
</CustomField>
積み上げ集計項目(主従関係のみ):
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Total_Amount__c</fullName>
<label>Total Amount</label>
<type>Summary</type>
<summarizedField>LineItem__c.Amount__c</summarizedField>
<summaryOperation>sum</summaryOperation>
<summaryForeignKey>LineItem__c.Order__c</summaryForeignKey>
</CustomField>
位置情報項目:
<type>Location</type>
<displayLocationInDecimal>true</displayLocationInDecimal>
<scale>6</scale>
グローバル値セット(再利用可能な選択リスト):
<GlobalValueSet xmlns="http://soap.sforce.com/2006/04/metadata">
<masterLabel>Industries</masterLabel>
<sorted>false</sorted>
<customValue><fullName>Technology</fullName><default>false</default><label>Technology</label></customValue>
<customValue><fullName>Healthcare</fullName><default>false</default><label>Healthcare</label></customValue>
</GlobalValueSet>
リレーションシップの種類
| 種類 | 削除時の動作 | 積み上げ集計 | 再親指定 | オブジェクトあたりの最大数 |
|---|---|---|---|---|
| 主従関係 | カスケード削除 | 可 | 設定可能 | 2 |
| 参照関係 | ブロック/クリア/制限 | 不可 | 該当なし | 40(標準オブジェクトは25) |
| 外部参照関係 | 該当なし | 不可 | 該当なし | - |
| 階層関係 | 該当なし | 不可 | 該当なし | 1(ユーザーのみ) |
| ジャンクション(多対多) | 2 つの主従関係 | 両方の親で利用可 | - | - |
レコードタイプ
<RecordType xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Enterprise</fullName>
<label>Enterprise</label>
<active>true</active>
<businessProcess>Enterprise Sales Process</businessProcess>
<description>For enterprise accounts</description>
</RecordType>
カスタムメタデータ型とカスタム設定の比較
| 機能 | カスタムメタデータ型 | カスタム設定(階層型) |
|---|---|---|
| デプロイ可能 | 可(メタデータ) | 不可(データ) |
| SOQL が必要 | はい(または getInstance) | いいえ(getOrgDefaults) |
| ユーザー/プロファイルによる上書き | 不可 | 可 |
| SOQL 制限にカウントされる | はい | いいえ |
| 用途 | 組織の設定、マッピング | ユーザー設定 |
権限セットグループ
<PermissionSetGroup xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Sales Team</label>
<permissionSets>
<permissionSet>Account_Manager</permissionSet>
<permissionSet>Opportunity_Editor</permissionSet>
<permissionSet>Report_Viewer</permissionSet>
</permissionSets>
</PermissionSetGroup>
SFDX ソースディレクトリ構成
force-app/main/default/
├── objects/
│ └── Invoice__c/
│ ├── Invoice__c.object-meta.xml
│ ├── fields/
│ │ ├── Amount__c.field-meta.xml
│ │ └── Status__c.field-meta.xml
│ ├── validationRules/
│ │ └── Amount_Must_Be_Positive.validationRule-meta.xml
│ └── listViews/
│ └── All.listView-meta.xml
├── permissionsets/
│ └── Invoice_Manager.permissionset-meta.xml
├── customPermissions/
│ └── Bypass_Automation.customPermission-meta.xml
└── layouts/
└── Invoice__c-Invoice Layout.layout-meta.xml
注意点
- オブジェクトあたりのカスタムリレーションシップは最大 40 個(標準オブジェクトは 25 個)
- 数式項目では、LongTextArea、RichTextArea、MultiSelectPicklist、Encrypted 項目を参照できません
- 積み上げ集計項目は主従関係でのみ使用でき、参照関係では使用できません
- グローバル値セットは共有後にローカルの選択リストに戻せません
- 暗号化テキスト項目は検索や並べ替えができません
- レコードタイプに応じた選択リストでは、レコードタイプごとに値を明示的にマッピングする必要があります
- 権限セットグループは非同期で再計算されるため、変更が適用されるまで数分かかることがあります
- カスタムメタデータ型のレコードは、本番環境で DML による作成・更新ができません。デプロイのみ可能です
- プロファイルはマージ時に競合が非常に発生しやすいため、すべての用途で権限セットを優先してください
参考資料
- スキーマリファレンス — 数式項目、積み上げ集計、位置情報、グローバル値セット、レコードタイプ、ページレイアウト、FlexiPages、カスタムメタデータ、プラットフォームイベント、Big Objects、クイックアクション、カスタム表示ラベル
ワークフロー
- オブジェクト/項目の要件を把握します
- SFDX ソース形式の XML ファイルを生成します
- 新しいオブジェクト/項目の権限セットを生成します
- まずスキーマをデプロイし、次にそれを参照するコードをデプロイします
- 次のコマンドで確認します:
sf org list metadata -m CustomObject --target-org myOrg
コメント
Markdown 対応