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

salesforce-report-creator

SF CLI経由でSalesforceレポートを作成するスキル。Metadata APIとREST APIの使い分け、フィールド命名規則、列数制限、レポートタイプ設定を網羅。カスタムオブジェクトレポート作成時の注意点も含む。

Use when creating Salesforce reports via CLI, deploying report types, or automating report generation.

インストール方法を見る

含まれるファイル(8)

  • SKILL.md12.2 KB
  • assets/report_metadata_template.xml1.8 KB
  • assets/report_type_template.xml2.6 KB
  • references/column_limits_guide.md3.6 KB
  • references/field_naming_rules.md4.4 KB
  • references/metadata_api_vs_rest_api.md4.7 KB
  • references/report_type_configuration.md6.3 KB
  • scripts/create_reports_via_api.py12.8 KB

SKILL.md(原文)

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

Salesforce Report Creator

SF CLIを使用してSalesforceレポートを作成・デプロイするためのスキル。

Overview

このスキルは以下の機能を提供します:

  1. レポートタイプの作成: カスタムオブジェクト用レポートタイプXMLの生成
  2. レポートの作成: Metadata APIまたはREST APIを使用したレポート作成
  3. フィールド管理: 適切なフィールド命名規則と列数制限の適用
  4. デプロイ: SF CLIを使用したSalesforce組織へのデプロイ

When to Use This Skill

以下の場面でこのスキルを使用してください:

  • SF CLIからSalesforceレポートを作成したい
  • カスタムオブジェクト用のレポートタイプを定義したい
  • 大量のフィールドを含むレポートを自動生成したい
  • Metadata APIとREST APIのどちらを使うべきか判断したい
  • レポートデプロイでエラーが発生し、トラブルシューティングが必要

トリガーフレーズ:

  • "Salesforceレポートを作成"
  • "SF CLIでレポートをデプロイ"
  • "カスタムレポートタイプを作成"
  • "レポートのフィールド参照エラー"

Prerequisites

必須ツール

# Salesforce CLI (sf) がインストールされていること
sf --version

# 認証済みのSalesforce組織があること
sf org list

認証

# Web認証フロー
sf org login web --alias myorg

# JWTフロー(CI/CD向け)
sf org login jwt --client-id <consumer-key> --jwt-key-file <path> --username <user>

# 既存の認証を確認
sf org display --target-org myorg

Core Concepts

1. Metadata API vs REST API

項目Metadata APIREST API (Analytics)
方式XMLファイルをデプロイHTTP POSTで直接作成
コマンドsf project deploy startPython/curlでAPI呼び出し
カスタムレポートタイプフィールド参照でエラーが発生しやすい推奨(安定動作)
保存場所force-app/main/default/reports/Salesforce組織内のみ
バージョン管理可能(GitでXML管理)不可(組織内のみ)

推奨事項:

  • 標準オブジェクト: Metadata APIで十分
  • カスタムオブジェクト: REST API推奨
  • CI/CD統合: Metadata API(バージョン管理可能)

2. フィールド命名規則

レポートでのフィールド参照形式はAPIによって異なります。

REST API形式:

Object.FieldName           # 基本形式
Object.Relationship.Name   # 関連オブジェクトのName表示

Metadata API (XML)形式:

Object.FieldName           # カスタムレポートタイプ
OBJECT.FIELDNAME           # 標準レポートタイプ(大文字)

Lookupフィールドの変換:

# APIフィールド名 → レポートフィールド名
"OwnerId"        → "Owner"
"RecordTypeId"   → "RecordType"
"CreatedById"    → "CreatedBy"
"LastModifiedById" → "LastModifiedBy"
"ParentId"       → "Parent"
"AccountId"      → "Account"
"ReportsToId"    → "ReportsTo"

関連オブジェクトの値表示:

# Owner名を表示したい場合
"Account.Owner.Name"    # ✓ 正しい
"Account.OwnerId"       # ✗ IDのみ表示

# Account名を表示したい場合
"Contact.Account.Name"  # ✓ 正しい
"Contact.AccountId"     # ✗ IDのみ表示

3. 列数制限

制限種別値適用場面
REST API detailColumns100列Analytics API
推奨設定値99列安全マージン
絶対最大200列Salesforce強制制限
SOQL文字数20,000文字クエリ制限

対応方法:

# 列数を99に制限
filtered_columns = columns[:99]

4. 除外すべきフィールド

以下のフィールドはレポートで使用できない場合があります:

EXCLUDED_FIELDS = {
    "IsDeleted",           # システムフィールド
    "MasterRecordId",      # マージ用
    "SystemModstamp",      # システム更新日時
    "LastActivityDate",    # 活動日
    "LastViewedDate",      # 参照日
    "LastReferencedDate",  # 参照日
    "Jigsaw", "JigsawCompanyId", "JigsawContactId",  # Data.com
    "PhotoUrl",            # 写真URL
    "CleanStatus",         # Data.comステータス
}

EXCLUDED_FIELD_TYPES = ["address", "location"]  # 複合フィールド
EXCLUDED_FIELD_SUFFIXES = ["__pc"]              # Person Account

Workflow

Step 1: レポートタイプの作成(カスタムオブジェクト用)

カスタムオブジェクトのレポートを作成するには、まずレポートタイプを定義します。

# フィールド一覧を取得
sf sobject describe --sobject Property__c --target-org myorg --json | \
  python3 -c "import sys,json; [print(f['name']) for f in json.load(sys.stdin)['fields']]"

レポートタイプXML例:

<?xml version="1.0" encoding="UTF-8"?>
<ReportType xmlns="http://soap.sforce.com/2006/04/metadata">
    <baseObject>Property__c</baseObject>
    <category>other</category>
    <deployed>true</deployed>
    <description>Property All Fields Report Type</description>
    <label>Property All Fields</label>
    <sections>
        <columns>
            <checkedByDefault>false</checkedByDefault>
            <field>Name</field>
            <table>Property__c</table>
        </columns>
        <!-- 追加のcolumns... -->
    </sections>
</ReportType>

カテゴリ選択:

  • accounts - Account関連
  • opportunities - Opportunity関連
  • cases - Case関連
  • leads - Lead関連
  • other - その他(カスタムオブジェクト)

Step 2: レポートタイプのデプロイ

# レポートタイプのみデプロイ
sf project deploy start \
  --source-dir force-app/main/default/reportTypes \
  --target-org myorg

# デプロイ結果確認
sf project deploy report --target-org myorg

Step 3: レポートの作成

方法A: REST API(推奨)

import json
import subprocess
import urllib.request

# 認証情報取得
result = subprocess.run(
    ["sf", "org", "display", "--target-org", "myorg", "--json"],
    capture_output=True, text=True
)
data = json.loads(result.stdout)
access_token = data['result']['accessToken']
instance_url = data['result']['instanceUrl']

# レポート作成
url = f"{instance_url}/services/data/v62.0/analytics/reports"
body = {
    "reportMetadata": {
        "name": "Property All Fields Report",
        "description": "All fields report for data verification",
        "reportFormat": "TABULAR",
        "reportType": {"type": "Property_All_Fields__c"},
        "detailColumns": [
            "Property__c.Name",
            "Property__c.CreatedDate",
            "Property__c.Owner.Name"
        ],
        "standardDateFilter": {
            "column": "Property__c.CreatedDate",
            "durationValue": "CUSTOM"
        }
    }
}

req = urllib.request.Request(
    url,
    data=json.dumps(body).encode('utf-8'),
    headers={
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json"
    },
    method='POST'
)

with urllib.request.urlopen(req) as resp:
    result = json.loads(resp.read().decode())
    print(f"Created report: {result['reportMetadata']['id']}")

方法B: Metadata API(XMLデプロイ)

<?xml version="1.0" encoding="UTF-8"?>
<Report xmlns="http://soap.sforce.com/2006/04/metadata">
    <columns>
        <field>Property__c.Name</field>
    </columns>
    <columns>
        <field>Property__c.CreatedDate</field>
    </columns>
    <description>Property All Fields Report</description>
    <format>Tabular</format>
    <name>Property All Fields</name>
    <reportType>Property_All_Fields__c</reportType>
    <scope>organization</scope>
    <showDetails>true</showDetails>
    <timeFrameFilter>
        <dateColumn>Property__c.CreatedDate</dateColumn>
        <interval>INTERVAL_CUSTOM</interval>
    </timeFrameFilter>
</Report>
sf project deploy start \
  --source-dir force-app/main/default/reports \
  --target-org myorg

Step 4: フォルダへの移動(オプション)

# REST APIでフォルダ移動
def move_report_to_folder(instance_url, access_token, report_id, folder_id):
    url = f"{instance_url}/services/data/v62.0/analytics/reports/{report_id}"
    body = {"reportMetadata": {"folderId": folder_id}}

    req = urllib.request.Request(
        url,
        data=json.dumps(body).encode('utf-8'),
        headers={
            "Authorization": f"Bearer {access_token}",
            "Content-Type": "application/json"
        },
        method='PATCH'
    )
    urllib.request.urlopen(req)

Troubleshooting

エラー: "Invalid field name: Object.FieldName"

原因: Metadata APIでカスタムレポートタイプのフィールド参照が正しくない

解決策:

  1. REST APIを使用する(推奨)
  2. フィールド名の形式を確認(Object.Field vs OBJECT.FIELD)

エラー: "Only a report with fewer than 100 columns can be run"

原因: REST APIの列数制限(100列)を超過

解決策:

# 列数を99に制限
columns = columns[:99]

エラー: "Could not find field OwnerId"

原因: Lookupフィールドの参照形式が間違っている

解決策:

# ✗ 間違い
"Account.OwnerId"

# ✓ 正しい
"Account.Owner"       # 関連オブジェクトとして参照
"Account.Owner.Name"  # Owner名を表示

エラー: "invalid report type"

原因: レポートタイプ名が一致しない、または__cサフィックスの問題

解決策:

# レポートタイプはSalesforce内で__cが付く
# XML: Property_All_Fields.reportType-meta.xml
# 参照時: Property_All_Fields__c

エラー: "Cannot find folder"

原因: レポートフォルダが存在しない

解決策:

# フォルダを先にデプロイ
sf project deploy start \
  --source-dir force-app/main/default/reports/MyFolder.reportFolder-meta.xml \
  --target-org myorg

Resources

リファレンスファイル

ファイル内容
references/metadata_api_vs_rest_api.mdAPI比較の詳細ガイド
references/field_naming_rules.mdフィールド命名規則の詳細
references/column_limits_guide.md列数制限と対応方法
references/report_type_configuration.mdレポートタイプ設定の詳細

スクリプト

ファイル用途
scripts/create_reports_via_api.pyREST APIでレポートを作成するPythonスクリプト

アセット(テンプレート)

ファイル用途
assets/report_type_template.xmlレポートタイプXMLテンプレート
assets/report_metadata_template.xmlレポートメタデータXMLテンプレート

Quick Reference

よく使うコマンド

# オブジェクトのフィールド一覧取得
sf sobject describe --sobject Account --target-org myorg --json

# レポートタイプのデプロイ
sf project deploy start --source-dir force-app/main/default/reportTypes --target-org myorg

# レポートのデプロイ
sf project deploy start --source-dir force-app/main/default/reports --target-org myorg

# デプロイ状況確認
sf project deploy report --target-org myorg

# 組織情報取得(認証トークン含む)
sf org display --target-org myorg --json

REST API エンドポイント

# レポート作成
POST /services/data/v62.0/analytics/reports

# レポート更新(フォルダ移動など)
PATCH /services/data/v62.0/analytics/reports/{reportId}

# レポートタイプ情報取得
GET /services/data/v62.0/analytics/reportTypes/{reportType}

レビュー

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

同じリポジトリのスキル

概要と使いどころ

action-status-updater

無料日本語概要

Track and update action item status from natural language updates like 'Seanのメールには返信しておいた' or 'Lu対応予定'. Integrates with daily-comms-ops workflow. Use when managing action items across communication channels.

takusaotome/claude-skills-library92026年10月5日 更新

ai-adoption-consultant

無料日本語概要

AI活用提案の専門コンサルタントスキル。LLM・AIエージェントの活用事例知識を基に、業界別、部門別、シーン別に最適なAI導入提案を行います。システム化、業務改善、効率化を得意とし、具体的な活用事例、期待効果、導入ステップを含む実践的な提案を提供します。Use when proposing AI/LLM adoption strategies for specific industries, departments, or business scenarios.

takusaotome/claude-skills-library92026年10月5日 更新

Generate AI-powered BPO service proposals for Japanese companies in the US market. Use when creating outsourcing proposals with AI service menus, ROI estimation, implementation roadmaps, and bilingual (JA/EN) proposal documents for 在米日系企業向けAI実装.

日本語の概要は準備中です。原文の説明を表示しています。

takusaotome/claude-skills-library92026年10月5日 更新

ai-text-humanizer

無料日本語概要

AI(LLM)が生成した日本語テキストの「AI臭」を検出・診断し、人間らしい文章にリライトするスキル。 Use when: 「AIっぽい文章を直して」「人間らしくリライトして」「AI臭を消して」「この文章をもっと自然にして」 「テキストのAI感を減らして」「機械っぽさを取りたい」 "make this sound more human", "remove AI tone", "humanize this text", "detect if this is AI-generated". 6つのAI特有パターン(視覚的マーカー、単調なリズム、マニュアル的構成、非コミット姿勢、抽象語の濫用、 定型メタファー)を正規表現ベースで検出し、0-100のAI臭スコアを算出。3つの人間化技法 (バランスを崩す・客観を崩す・論理を崩す)でリライトを実行する。 Note: 検出スクリプトは日本語テキスト専用。英語テキストの場合はClaude自身がreferences/を参照して分析・リライトする。

takusaotome/claude-skills-library92026年10月5日 更新

Generate audit-ready internal control design documents from As-Is business process inventories. Produces control IDs, assertion mappings, procedures, SoD analysis, KPIs, materiality thresholds, and implementation roadmaps. Use when building internal controls for new audit engagements, SOX/J-SOX compliance, or process improvement initiatives.

日本語の概要は準備中です。原文の説明を表示しています。

takusaotome/claude-skills-library92026年10月5日 更新

Review audit-related documents (control design documents, bottleneck analyses, requirements definitions, etc.) for quality, scoring them 0-100 with a severity-rated findings list. Use when reviewing audit documents, checking control design quality, or verifying cross-document consistency. Supports documents governed by US GAAP, IFRS, or J-GAAP.

日本語の概要は準備中です。原文の説明を表示しています。

takusaotome/claude-skills-library92026年10月5日 更新

takusaotome のスキルをすべて見る

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