• Projects
  • Service
  • About
  • branding.bz
  • Podcast
  • Tips
  • FAQ
  • Recruit
  • Download
  • Contact
  • branding.bz(ブランド構築SaaS)
  • DESIGN NOW(デザインメディア)
  • X
  • LinkedIn
  • Spotify
  • Facebook

213-0011 神奈川県川崎市高津区久本3-6-7-303

© 2026 ID INC. All rights reserved

claude-skills/スキル
SKILLOfficialdevelopment

platform-soql-query

プラグイン
salesforce-development
ソース
GitHub で見る ↗
説明

SOQL クエリ(Salesforce データベース照会言語)の生成、最適化、分析機能で、100段階のスコア評価を提供します。 **次のような場合に使用:** - ユーザーが SOQL/SOSL(検索言語)の作成や最適化を必要としているとき - 自然言語からクエリへの変換、リレーションシップクエリ(複数のデータ表間の関連付け照会)、集計処理、クエリ実行計画の分析、Salesforce クエリのパフォーマンス向上やセキュリティ改善が必要なとき **トリガー条件(このスキルを起動する場面):** - ユーザーが SOQL/SOSL クエリを作成・最適化・デバッグしているとき - .soql ファイルに触れるとき - リレーションシップクエリ、集計処理、クエリのパフォーマンスについて質問するとき **トリガーしない条件(別のスキルを使う場面):** - 大量データ操作が必要な場合(platform-data-manage を使用) - Apex DML ロジック(データベース変更操作のプログラミング処理)が関わる場合(platform-apex-generate を使用) - レポートやダッシュボードのクエリの場合

原文を表示

SOQL query generation, optimization, and analysis with 100-point scoring. Use this skill when the user needs SOQL/SOSL authoring or optimization: natural-language-to-query generation, relationship queries, aggregates, query-plan analysis, and performance or safety improvements for Salesforce queries. TRIGGER when: user writes, optimizes, or debugs SOQL/SOSL queries, touches .soql files, or asks about relationship queries, aggregates, or query performance. DO NOT TRIGGER when: bulk data operations (use platform-data-manage), Apex DML logic (use platform-apex-generate), or report/dashboard queries.

ユースケース
  • SOQL/SOSLクエリを作成・最適化する
  • 自然言語からクエリに変換する
  • リレーションシップクエリを構築する
  • クエリのパフォーマンスを向上させる
  • クエリのセキュリティを改善する
本文(日本語訳)

platform-soql-query: Salesforce SOQL クエリ専門家

次のような場合に使用: ユーザーがSOQL/SOSL(Salesforceのデータ問い合わせ言語)の作成や最適化を必要とする場合。自然言語からクエリへの変換、関連データの問い合わせ、集約処理、クエリ実行計画の分析、Salesforceクエリのパフォーマンスと安全性の向上に対応します。

このスキルが担当する作業

platform-soql-queryを使用するのは以下の場合です:

  • .soqlファイル
  • 自然言語からのクエリ生成
  • 関連データや集約クエリの問い合わせ
  • クエリの最適化と選択性(どれだけ効率よく対象データを絞り込めるか)の分析
  • SOQL/SOSLの構文と、Salesforceの処理制限(ガバナー制限)に対応した設計

以下の場合は他のスキルに任せます:

  • 大量のデータ操作を行う場合 → platform-data-manage
  • クエリのロジックをApex(Salesforceのプログラミング言語)内に組み込む場合 → platform-apex-generate
  • ログの分析によってデバッグする場合 → platform-apex-logs-debug

最初に確認するべき情報

以下のことを質問したり推測したりします:

  • 対象となるオブジェクト(データの種類)
  • 必要なフィールド(データの項目)
  • 絞り込み条件
  • ソート・件数制限の要件
  • クエリの用途(表示用、自動化用、分析用、Apexからの実行用など)
  • パフォーマンス・選択性がすでに問題になっているか

推奨される流れ

1. 最もシンプルで正確なクエリを作成する

優先事項:

  • 必要なフィールドのみを指定
  • 明確な WHERE(絞り込み)条件
  • 適切な LIMIT(件数制限)
  • 必要な分だけの関連データの深さ

作成中は mcp__plugin_salesforce-development_salesforce-lsp__complete_soql を呼び出して、部分的なクエリに対して接続先の組織(Org)のスキーマ(データ構造)に基づいた補完を受けます。これにより、存在しないAPI名を後で修正する手間が減ります。エラーが出た場合やツールが登録されていない場合は、references/soql-syntax-reference.mdの構文リファレンスを参照してください。

すでにApexクラス内にクエリがある場合(新規作成ではなく既存クエリの最適化やデバッグ)は、mcp__plugin_salesforce-development_salesforce-lsp__extract_soql_from_apex を呼び出して .cls ファイルからSOQLを抽出し、実際に実行されるクエリを正確に分析します。

2. 適切なクエリの形式を選ぶ

目的 使用すべきパターン
子データから親データを取得 子から親への関連付け遡上
親データから子行を取得 サブクエリ(内部クエリ)
件数・合計値 集約クエリ
関連データがある/ない行 セミジョイン/アンチジョイン(特殊なフィルタ)
複数オブジェクト間のテキスト検索 SOSL

3. LSP ツールで検証する(必須)

必須: SOQL クエリを組織に対して実行したり、本番運用を推奨する前に:

  1. mcp__plugin_salesforce-development_salesforce-lsp__validate_soql を呼び出してクエリ文字列をチェックし、実行前にパースエラーを捉えます。

    • 成功時({ok: true})は進めます。クリーンなパースはクリーンなクエリではありません。 validate_soql はパーサーのみです。ターゲット組織に存在しないオブジェクト・フィールド・関連付けでもパスします。成功は「構文が正しい」という意味であり、「識別子が実在する」という意味ではありません。
    • 不確実な結果では必ず失敗扱い。 呼び出しがタイムアウトしたか、リトライされたか、結果が不確実な場合、成功と見なさず、ステップ2にフォールバックし、validate_soql=unavailable: timeoutと記録します。
    • エラーメッセージ({error: <code>})の場合、validate_soql=unavailable: <code>と記録してステップ2にフォールバックします。
    • ツールが登録されていない場合、validate_soql=unavailable: lsp_not_presentと記録してステップ2にフォールバックします。
  2. 組織スキーマに対して識別子を検証(必須、パース成功時も実施)。 クエリ内のすべてのオブジェクト・フィールド・関連付けが実際にターゲット組織に存在することを確認した後で推奨します。正しくパースされた存在しないフィールドは、有効と報告してはいけません。

    • 確実な確認方法 — describe または制限付きプローブ。ユーザーの完全なクエリを実行してスキーマ検証しないでください(制限のないクエリなら大量の行を取得する可能性があります)。代わりに:
      • 推奨: クエリ内の各オブジェクトに対して sf sobject describe --sobject <Object> --target-org <org> を実行し、参照されるすべてのフィールド・関連付けが describe 出力に含まれていることを確認。識別子を行取得なしで解決します。
      • 別案: 制限付き組織ベースのプローブ — LIMIT 0(または LIMIT 1)に書き換えたクエリを sf data query --query "<bounded-query>" --json --target-org <org> で実行。LIMIT 0はすべての識別子をサーバー側で検証しながら行を返しません。不正なオブジェクト・フィールドは INVALID_TYPE / INVALID_FIELD エラーとして浮き彫りになります。
    • mcp__plugin_salesforce-development_salesforce-lsp__complete_soql は作成時に名前を解決するのに使えますが、補完は現在位置の候補を返すだけで、すべての識別子の検証結果ではありません。また {ok: true, hint: "no_org_connected"} でプレースホルダースキーマを返すことがあります。補完出力は十分なスキーマ検証ではありません。complete_soql が no_org_connected を返すか、すべての識別子を解決しなかった場合、前述の describe またはプローブ確認にフォールバックします。
    • 検証が実行されなかったり、パースのみだからという理由で、クエリを有効と報告しないでください。 スキーマに対する識別子確認を常に優先します。
  3. 本番クエリの場合、mcp__plugin_salesforce-development_salesforce-lsp__check_soql_selectivity を呼び出して選択性ヒューリスティクス(効率判定)を分析してから、大量のデータ処理や定期実行を推奨します。

    • エラーメッセージ出力やツール未登録の場合、check_soql_selectivity=unavailable: <code>と記録し、選択性が検証されなかったことを注記します。
  4. スキーマ変更を展開した後、フィールドやオブジェクト参照が展開直後に検証失敗する場合、mcp__plugin_salesforce-development_salesforce-lsp__refresh_org_schema を呼び出してキャッシュされた組織の describe を無効化し、コードエラーと断定する前に再検証します。

LSP 統合の完全な仕様とエラーコード参照は platform-lsp-integrate スキルをご覧ください。

4. 選択性とセキュリティを最適化する

確認項目:

  • インデックス対応・選択的なフィルタ
  • 不要なフィールドの除外
  • 大量スキャンやワイルドカードの回避
  • セキュリティ実装の期待値

5. 実行経路が必要な場合に検証

ユーザーが実行時検証を希望する場合は、以下に任せます:

  • platform-data-manage

重要な原則

  • SELECT * の思考法は使わない。必要なフィールドのみを問い合わせる
  • Apex のループ内でクエリを実行しない
  • Apexでのフィルタ後処理より、SOQL 内でのフィルタを優先
  • 不要な行の読み込みより、集約関数で件数・集計を計算する
  • ワイルドカード(%test% など)は慎重に評価。先頭のワイルドカードはインデックスを無効化しやすい
  • クエリを Apex に移動させるときは、セキュリティモード・フィールドアクセス要件を考慮

出力形式

完成時は以下の順で報告します:

  1. クエリの目的
  2. 最終的な SOQL/SOSL
  3. この形式を選んだ理由
  4. 最適化またはセキュリティに関する注記
  5. 必要に応じて実行の提案

推奨される形式 — 正確な構文は references/soql-syntax-reference.md を参照:

クエリの目的: <概要>
クエリ: <soql または sosl>
設計: <関連付け・集約・フィルタの選択>
注記: <選択性、制限、セキュリティ、ガバナー制限対応>
次のステップ: <platform-data-manage で実行または Apex に組み込み>

スキル間の連携

目的 任せるスキル 理由
組織に対してクエリを実行 platform-data-manage 実行とエクスポート
クエリをサービス・セレクタに組み込み platform-apex-generate 実装コンテキスト
ログから低速クエリの症状を分析 platform-apex-logs-debug 実行時の証拠
クエリ連動UI を構築 experience-lwc-generate フロントエンド統合

スコア評価ガイド

スコア 意味
90以上 本番環境対応の最適化クエリ
80–89 良好なクエリ。細かい改善の余地あり
70–79 機能するがパフォーマンス懸念あり
70未満 本番使用前の改訂が必須

リファレンスファイル一覧

ファイル 参照時期
references/soql-syntax-reference.md 構文・演算子・日付リテラル・関連クエリパターン
references/query-optimization.md 選択性ルール・インデックス戦略・ガバナー制限・セキュリティパターン
references/soql-reference.md クイックリファレンス — 演算子・日付関数・集約関数・WITH句
references/anti-patterns.md SOQL の一般的なミスと修正方法 — クエリ確定前に必読
references/selector-patterns.md Apex セレクタ層パターン — クエリを Apex クラスに組み込むときに参照
references/field-coverage-rules.md フィールドカバレッジ検証 — Apex コード内で使用する SOQL を生成するときに参照
references/cli-commands.md sf CLI のクエリ実行・一括エクスポート・クエリ計画コマンド
assets/basic-queries.soql 一般的なオブジェクトのスタータークエリ例
assets/relationship-queries.soql 親から子・子から親の関連クエリパターン
assets/aggregate-queries.soql COUNT・SUM・GROUP BY・ROLLUP クエリパターン
assets/optimization-patterns.soql 選択的フィルタとインデックス対応クエリパターン
assets/bulkified-query-pattern.cls トリガーコンテキスト向け Apex Map ベース一括クエリパターン
assets/selector-class.cls セレクタクラスの完全実装テンプレート
scripts/post-tool-validate.py ポスト書き込みフック — .soql ファイル編集後に静的検証とライブクエリ計
原文(English)を表示

platform-soql-query: Salesforce SOQL Query Expert

Use this skill when the user needs SOQL/SOSL authoring or optimization: natural-language-to-query generation, relationship queries, aggregates, query-plan analysis, and performance/safety improvements for Salesforce queries.

When This Skill Owns the Task

Use platform-soql-query when the work involves:

  • .soql files
  • query generation from natural language
  • relationship queries and aggregate queries
  • query optimization and selectivity analysis
  • SOQL/SOSL syntax and governor-aware design

Delegate elsewhere when the user is:

  • performing bulk data operations → platform-data-manage
  • embedding query logic inside broader Apex implementation → platform-apex-generate
  • debugging via logs rather than query shape → platform-apex-logs-debug

Required Context to Gather First

Ask for or infer:

  • target object(s)
  • fields needed
  • filter criteria
  • sort / limit requirements
  • whether the query is for display, automation, reporting-like analysis, or Apex usage
  • whether performance / selectivity is already a concern

Recommended Workflow

1. Generate the simplest correct query

Prefer:

  • only needed fields
  • clear WHERE criteria
  • reasonable LIMIT when appropriate
  • relationship depth only as deep as necessary

While drafting, call mcp__plugin_salesforce-development_salesforce-lsp__complete_soql with the partial query to get schema-aware completion of object, field, and relationship names against the connected org — this avoids guessing API names that then fail validation. On error envelope or unavailable ({error: <code>} / tool not registered), skip completion and rely on the syntax reference in references/soql-syntax-reference.md.

When the query already lives inside an Apex class (optimizing or debugging embedded SOQL rather than authoring new), call mcp__plugin_salesforce-development_salesforce-lsp__extract_soql_from_apex with the .cls file to pull the SOQL strings out before analyzing them, so you optimize the exact query the class runs.

2. Choose the right query shape

Need Default pattern
parent data from child child-to-parent traversal
child rows from parent subquery
counts / rollups aggregate query
records with / without related rows semi-join / anti-join
text search across objects SOSL

3. Validate with LSP tools (REQUIRED)

REQUIRED: Before running a SOQL query against the org or recommending it for production use:

  1. Call mcp__plugin_salesforce-development_salesforce-lsp__validate_soql with the query string to check syntax and catch parse errors before execution.

    • On success ({ok: true}), proceed. A clean parse is not a clean query. validate_soql is parser-only — it accepts objects, fields, and relationships that do not exist in the target org. A successful parse means the syntax is well-formed, NOT that the identifiers resolve.
    • Fail closed on an uncertain result. If the call timed out, was retried, or its result is otherwise uncertain, do NOT treat it as a successful validation — fall back to step 2 and record validate_soql=unavailable: timeout.
    • On error envelope ({error: <code>}), record validate_soql=unavailable: <code> and fall back to step 2.
    • On unavailable (tool not registered), record validate_soql=unavailable: lsp_not_present and fall back to step 2.
  2. Verify identifiers against org schema (REQUIRED, even when the parse succeeds). Confirm every object, field, and relationship in the query actually exists in the target org before recommending it — a well-formed parse over a nonexistent field must not be reported as valid.

    • Authoritative check — describe or a bounded probe. Do NOT execute the user's full query to verify schema (it may be unbounded and retrieve large result sets). Instead:
      • Preferred: sf sobject describe --sobject <Object> --target-org <org> for each object in the query, and confirm every referenced field/relationship appears in the describe output. This resolves identifiers with no rows retrieved.
      • Alternative: a bounded org-backed probe — the same query rewritten with LIMIT 0 (or the object's key with LIMIT 1) via sf data query --query "<bounded-query>" --json --target-org <org>. LIMIT 0 validates every identifier server-side while returning no rows; a bad object or field surfaces as an INVALID_TYPE / INVALID_FIELD error.
    • mcp__plugin_salesforce-development_salesforce-lsp__complete_soql may be used to resolve names while drafting, but completion returns candidates at a cursor position — not a validation result for every identifier — and can return {ok: true, hint: "no_org_connected"} with placeholder schema. Completion output is NOT sufficient schema verification: if complete_soql returns no_org_connected or does not resolve every identifier, fall back to the describe or bounded-probe check above.
    • NEVER report a query as valid because the validation check didn't run or only parsed — always confirm identifiers against the org schema first.
  3. For production queries, also call mcp__plugin_salesforce-development_salesforce-lsp__check_soql_selectivity to analyze selectivity heuristics before recommending the query for high-volume or scheduled use.

    • On error envelope or unavailable, record check_soql_selectivity=unavailable: <code> and note selectivity was not verified.
  4. After deploying schema changes, if a field or object reference fails validation immediately after deployment, call mcp__plugin_salesforce-development_salesforce-lsp__refresh_org_schema to invalidate the cached org describe, then re-validate before assuming a code error.

See the platform-lsp-integrate skill for the complete LSP Call/Fallback Contract and error code reference.

4. Optimize for selectivity and safety

Check:

  • indexed / selective filters
  • no unnecessary fields
  • no avoidable wildcard or scan-heavy patterns
  • security enforcement expectations

5. Validate execution path if needed

If the user wants runtime verification, hand off execution to:

  • platform-data-manage

High-Signal Rules

  • never use SELECT * style thinking; query only required fields
  • do not query inside loops in Apex contexts
  • prefer filtering in SOQL rather than post-filtering in Apex
  • use aggregates for counts and grouped summaries instead of loading unnecessary records
  • evaluate wildcard usage carefully; leading wildcards often defeat indexes
  • account for security mode / field access requirements when queries move into Apex

Output Format

When finishing, report in this order:

  1. Query purpose
  2. Final SOQL/SOSL
  3. Why this shape was chosen
  4. Optimization or security notes
  5. Execution suggestion if needed

Suggested shape — use references/soql-syntax-reference.md for exact syntax:

Query goal: <summary>
Query: <soql or sosl>
Design: <relationship / aggregate / filter choices>
Notes: <selectivity, limits, security, governor awareness>
Next step: <run in platform-data-manage or embed in Apex>

Cross-Skill Integration

Need Delegate to Reason
run the query against an org platform-data-manage execution and export
embed the query in services/selectors platform-apex-generate implementation context
analyze slow-query symptoms from logs platform-apex-logs-debug runtime evidence
wire query-backed UI experience-lwc-generate frontend integration

Score Guide

Score Meaning
90+ production-optimized query
80–89 good query with minor improvements possible
70–79 functional but performance concerns remain
< 70 needs revision before production use

Reference File Index

File When to read
references/soql-syntax-reference.md Syntax, operators, date literals, relationship query patterns
references/query-optimization.md Selectivity rules, indexing strategy, governor limits, security patterns
references/soql-reference.md Quick reference — operators, date functions, aggregate functions, WITH clauses
references/anti-patterns.md Common SOQL mistakes and their fixes — read before finalizing any query
references/selector-patterns.md Apex selector layer patterns — read when embedding queries in Apex classes
references/field-coverage-rules.md Field coverage validation — read when generating SOQL used inside Apex code
references/cli-commands.md sf CLI query execution, bulk export, query plan commands
assets/basic-queries.soql Starter query examples for common objects
assets/relationship-queries.soql Parent-to-child and child-to-parent relationship query patterns
assets/aggregate-queries.soql COUNT, SUM, GROUP BY, ROLLUP query patterns
assets/optimization-patterns.soql Selective filter and index-aware query patterns
assets/bulkified-query-pattern.cls Apex Map-based bulk query pattern for trigger contexts
assets/selector-class.cls Full selector class implementation template
scripts/post-tool-validate.py Post-write hook — runs static SOQL validation and live query plan analysis after .soql file edits

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。