mcpField
S
sf-schema

sf-schema

github.com/clientell-aiデータ・データベース20103 回インストール32 週間前に更新
リポジトリ

sf-schema について

Salesforce の開発者やメタデータ担当者向けのスキーマ設計スキルです。オブジェクト、項目、ルール、権限の SFDX ソース形式メタデータの作成を案内し、リレーションの制約やデプロイ時の注意点も扱います。

主な機能

  1. 01カスタムオブジェクトメタデータの生成
  2. 02項目と入力規則の定義
  3. 03権限とレコードタイプの設定
  4. 04リレーションの制約の説明
  5. 05SFDX デプロイ手順の提示

活用シーン

  1. 01オブジェクトと項目の作成
  2. 02新しいスキーマへの権限設定
  3. 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 &amp; ' - ' &amp; 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 &lt;= 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 &amp; ' ' &amp; 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、クイックアクション、カスタム表示ラベル

ワークフロー

  1. オブジェクト/項目の要件を把握します
  2. SFDX ソース形式の XML ファイルを生成します
  3. 新しいオブジェクト/項目の権限セットを生成します
  4. まずスキーマをデプロイし、次にそれを参照するコードをデプロイします
  5. 次のコマンドで確認します:sf org list metadata -m CustomObject --target-org myOrg

コメント