description: Explore the Salesforce GraphQL schema via grep-only lookups. Use before generating any GraphQL query — schema exploration must complete first.
paths:
- "**/*.ts"
- "**/*.tsx"
- "**/*.graphql"
---
# Salesforce GraphQL Schema Exploration
Guidance for AI agents working with the Salesforce GraphQL API schema. **GREP ONLY** — the schema file is very large (~265,000+ lines). All lookups MUST use grep; do NOT open, read, stream, or parse the file.
The schema reflects the **current org state**. Custom objects and fields appear only after metadata is deployed.
- **Before** running `npm run graphql:schema`: Deploy all metadata (objects, permission sets, layouts) and assign the permission set to the target user. Invoke the `deploying-to-salesforce` skill for the full sequence.
- **After** any metadata deployment: Re-run `npm run graphql:schema` and `npm run graphql:codegen` so types and queries stay in sync.
**Location:** `schema.graphql` at the **SFDX project root** (NOT inside the webapp dir). All grep commands **must be run from the project root** where `schema.graphql` lives.
> ⚠️ **Important (Access Policy - GREP ONLY)**: Do NOT open, view, stream, paginate, or parse the schema with any tool other than grep. All lookups MUST be done via grep using anchored patterns with minimal context as defined below.
If the file is not present, generate it by running (from the **webapp dir**, not the project root):
```bash
# Run from webapp dir (force-app/main/default/webapplications/<app-name>/)
npm run graphql:schema
```
**BEFORE generating any GraphQL query, you MUST:**
1.**Check if schema exists**: Look for `schema.graphql` in the **SFDX project root**
2.**If schema is missing**:
-`cd` to the **webapp dir** and run `npm run graphql:schema` to download it
- Wait for the command to complete successfully
- Then proceed with grep-only lookups as defined below.
3.**If schema exists**: Proceed with targeted searches as described below
> ⚠️ **DO NOT** generate GraphQL queries without first having access to the schema. Standard field assumptions may not match the target org's configuration.
## Schema Structure Overview
Main entry points: `Query { uiapi }` for reads; `Mutation { uiapi(input: ...) }` for creates/updates/deletes. Record queries use `uiapi.query.<ObjectName>`.
## Allowed Lookups (grep-only)
Use ONLY these grep commands to locate specific definitions in schema.graphql. Do not use editors (VS Code/vim/nano), cat/less/more/head/tail, or programmatic parsers (node/python/awk/sed/jq).
- Always include:
-`-n` (line numbers) and `-E` (extended regex)
- Anchors (`^`) and word boundaries (`\b`)
- Minimal context with `-A N` (prefer the smallest N that surfaces the needed lines)
### 1. Find Available Fields for a Record Type
Search for `type <ObjectName> implements Record` to find all queryable fields:
1.**Identify the target object** (e.g., Account, Contact, Opportunity)
2.**Run the "Find Available Fields" grep command** for your object (copy only the field names visible in the grep output; do not open the file)
3.**Run the "Find Filter Options" grep command** (`<Object>_Filter`) to understand filtering options
4.**Run the "Find OrderBy Options" grep command** (`<Object>_OrderBy`) for sorting capabilities
5.**Build the query** following the patterns in the `generating-graphql-read-query` or `generating-graphql-mutation-query` skill using only values returned by grep
6.**Validate field names** using grep matches (case-sensitive). Do not open or parse the file beyond grep.
## Tips for Agents
- **Always verify field names** by running the specific grep commands; do not open the schema file
- **Use grep with anchors and minimal -A context** to explore the schema efficiently—never read or stream the file
- **Check relationships** by looking for `parentRelationship` and `childRelationship` comments in type definitions
- **Look for Connection types** (e.g., `AccountConnection`) via grep to understand pagination structure
- **Custom objects** end with `__c` (e.g., `CustomObject__c`)
- **Custom fields** also end with `__c` (e.g., `Custom_Field__c`)
## Forbidden Operations
To prevent accidental large reads, the following are prohibited for schema.graphql: