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(Salesforceのデータ問い合わせ言語)の作成や最適化を必要とする場合。自然言語からクエリへの変換、関連データの問い合わせ、集約処理、クエリ実行計画の分析、Salesforceクエリのパフォーマンスと安全性の向上に対応します。
platform-soql-queryを使用するのは以下の場合です:
.soqlファイル以下の場合は他のスキルに任せます:
以下のことを質問したり推測したりします:
優先事項:
作成中は 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を抽出し、実際に実行されるクエリを正確に分析します。
| 目的 | 使用すべきパターン |
|---|---|
| 子データから親データを取得 | 子から親への関連付け遡上 |
| 親データから子行を取得 | サブクエリ(内部クエリ) |
| 件数・合計値 | 集約クエリ |
| 関連データがある/ない行 | セミジョイン/アンチジョイン(特殊なフィルタ) |
| 複数オブジェクト間のテキスト検索 | SOSL |
必須: SOQL クエリを組織に対して実行したり、本番運用を推奨する前に:
mcp__plugin_salesforce-development_salesforce-lsp__validate_soql を呼び出してクエリ文字列をチェックし、実行前にパースエラーを捉えます。
{ok: true})は進めます。クリーンなパースはクリーンなクエリではありません。 validate_soql はパーサーのみです。ターゲット組織に存在しないオブジェクト・フィールド・関連付けでもパスします。成功は「構文が正しい」という意味であり、「識別子が実在する」という意味ではありません。validate_soql=unavailable: timeoutと記録します。{error: <code>})の場合、validate_soql=unavailable: <code>と記録してステップ2にフォールバックします。validate_soql=unavailable: lsp_not_presentと記録してステップ2にフォールバックします。組織スキーマに対して識別子を検証(必須、パース成功時も実施)。 クエリ内のすべてのオブジェクト・フィールド・関連付けが実際にターゲット組織に存在することを確認した後で推奨します。正しくパースされた存在しないフィールドは、有効と報告してはいけません。
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 またはプローブ確認にフォールバックします。本番クエリの場合、mcp__plugin_salesforce-development_salesforce-lsp__check_soql_selectivity を呼び出して選択性ヒューリスティクス(効率判定)を分析してから、大量のデータ処理や定期実行を推奨します。
check_soql_selectivity=unavailable: <code>と記録し、選択性が検証されなかったことを注記します。スキーマ変更を展開した後、フィールドやオブジェクト参照が展開直後に検証失敗する場合、mcp__plugin_salesforce-development_salesforce-lsp__refresh_org_schema を呼び出してキャッシュされた組織の describe を無効化し、コードエラーと断定する前に再検証します。
LSP 統合の完全な仕様とエラーコード参照は platform-lsp-integrate スキルをご覧ください。
確認項目:
ユーザーが実行時検証を希望する場合は、以下に任せます:
SELECT * の思考法は使わない。必要なフィールドのみを問い合わせる%test% など)は慎重に評価。先頭のワイルドカードはインデックスを無効化しやすい完成時は以下の順で報告します:
推奨される形式 — 正確な構文は 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 ファイル編集後に静的検証とライブクエリ計 |
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.
Use platform-soql-query when the work involves:
.soql filesDelegate elsewhere when the user is:
Ask for or infer:
Prefer:
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.
| 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 |
REQUIRED: Before running a SOQL query against the org or recommending it for production use:
Call mcp__plugin_salesforce-development_salesforce-lsp__validate_soql with the query string to check syntax and catch parse errors before execution.
{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.validate_soql=unavailable: timeout.{error: <code>}), record validate_soql=unavailable: <code> and fall back to step 2.validate_soql=unavailable: lsp_not_present and fall back to step 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.
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.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.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.
check_soql_selectivity=unavailable: <code> and note selectivity was not verified.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.
Check:
If the user wants runtime verification, hand off execution to:
SELECT * style thinking; query only required fieldsWhen finishing, report in this order:
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>
| 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 | 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 |
| 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 による自動翻訳です。