forcedotcom/sf-skills / plugins/builder/salesforce-development/skills/platform-data-manage
platform-data-manage
VerifiedSalesforce data operations with 130-point scoring. Use to create, update, delete, bulk import/export, generate test data, and clean up org records via sf CLI and anonymous Apex. TRIGGER on creating test data, bulk import/export, sf data CLI commands, data-factory patterns for Apex tests, or seeding/cleaning org records. DO NOT TRIGGER for SOQL query writing only (use platform-soql-query), Apex test execution (use platform-apex-test-run), or metadata deployment (use platform-metadata-deploy).
references/soql-relationship-guide.md
View on GitHub<!-- Parent: platform-data-manage/SKILL.md -->
# SOQL Relationship Query Guide
Complete reference for querying related records in Salesforce.
## Relationship Types
### 1. Parent-to-Child (Subquery)
Returns parent records with nested child records.
```sql
SELECT Id, Name,
(SELECT Id, FirstName, LastName FROM Contacts)
FROM Account
WHERE Industry = 'Technology'
```
**Key Points:**
- Maximum 20 subqueries per query
- Use relationship name (plural): `Contacts`, `Opportunities`, `Cases`
- For custom objects: `Child_Object__r`
### 2. Child-to-Parent (Dot Notation)
Access parent fields from child record.
```sql
SELECT Id, Name,
Account.Name,
Account.Industry,
Account.Owner.Name
FROM Contact
WHERE Account.Type = 'Customer'
```
**Key Points:**
- Maximum 5 levels deep
- Standard: `Account.Name`
- Custom: `Parent__r.Name`
### 3. Polymorphic (TYPEOF)
Handle fields that reference multiple object types.
```sql
SELECT Id, Subject,
TYPEOF Who
WHEN Contact THEN FirstName, LastName
WHEN Lead THEN Company
END,
TYPEOF What
WHEN Account THEN Name, Industry
WHEN Opportunity THEN Amount
END
FROM Task
```
**Common Polymorphic Fields:**
- `WhoId` → Contact, Lead
- `WhatId` → Account, Opportunity, Case, etc.
- `OwnerId` → User, Queue
## Relationship Names
| Child Object | Parent Field | Relationship Name |
|--------------|--------------|-------------------|
| Contact | AccountId | Account.Contacts |
| Opportunity | AccountId | Account.Opportunities |
| Case | AccountId | Account.Cases |
| Task | WhatId | Account.Tasks |
| Contact | ReportsToId | Contact.ReportsTo |
## Limits
| Limit | Value |
|-------|-------|
| Child-to-Parent depth | 5 levels |
| Subqueries per query | 20 |
| Rows per subquery | 200 (without LIMIT) |
## Best Practices
1. **Use indexed fields** in WHERE clauses
2. **Add LIMIT** to subqueries
3. **Filter early** - push conditions into subqueries
4. **Avoid N+1** - use relationship queries instead of loops
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |