Salesforce Developer
Core Workflow
- Analyze requirements - Understand business needs, data model, governor limits, scalability
- Design solution - Choose declarative vs programmatic, plan bulkification, design integrations
- Implement - Write Apex classes, LWC components, SOQL queries with best practices
- Validate governor limits - Verify SOQL/DML counts, heap size, and CPU time stay within platform limits before proceeding
- Test thoroughly - Write test classes with 90%+ coverage, test bulk scenarios (200-record batches)
- Deploy - Use Salesforce DX, scratch orgs, CI/CD for metadata deployment
Reference Guide
Load detailed guidance based on context:
| Topic |
Reference |
Load When |
| Apex Development |
references/apex-development.md |
Classes, triggers, async patterns, batch processing |
| Lightning Web Components |
references/lightning-web-components.md |
LWC framework, component design, events, wire service |
| SOQL/SOSL |
references/soql-sosl.md |
Query optimization, relationships, governor limits |
| Integration Patterns |
references/integration-patterns.md |
REST/SOAP APIs, platform events, external services |
| Deployment & DevOps |
references/deployment-devops.md |
Salesforce DX, CI/CD, scratch orgs, metadata API |
Constraints
MUST DO
- Bulkify Apex code — collect IDs/records before loops, query/DML outside loops
- Write test classes with minimum 90% code coverage, including bulk scenarios
- Use selective SOQL queries with indexed fields; leverage relationship queries
- Use appropriate async processing (batch, queueable, future) for long-running work
- Implement proper error handling and logging; use
Database.update(scope, false) for partial success
- Use Salesforce DX for source-driven development and metadata deployment
MUST NOT DO
- Execute SOQL/DML inside loops (governor limit violation — see bulkified trigger pattern below)
- Hard-code IDs or credentials in code
- Create recursive triggers without safeguards
- Skip field-level security and sharing rules checks
- Use deprecated Salesforce APIs or components
Code Patterns
Bulkified Trigger (Correct Pattern)
// CORRECT: collect IDs, query once outside the loop
trigger AccountTrigger on Account (before insert, before update) {
AccountTriggerHandler.handleBeforeInsert(Trigger.new);
}
public class AccountTriggerHandler {
public static void handleBeforeInsert(List<Account> newAccounts) {
Set<Id> parentIds = new Set<Id>();
for (Account acc : newAccounts) {
if (acc.ParentId != null) parentIds.add(acc.ParentId);
}
Map<Id, Account> parentMap = new Map<Id, Account>(
[SELECT Id, Name FROM Account WHERE Id IN :parentIds]
);
for (Account acc : newAccounts) {
if (acc.ParentId != null && parentMap.containsKey(acc.ParentId)) {
acc.Description = 'Child of: ' + parentMap.get(acc.ParentId).Name;
}
}
}
}
// INCORRECT: SOQL inside loop — governor limit violation
trigger AccountTrigger on Account (before insert) {
for (Account acc : Trigger.new) {
Account parent = [SELECT Id, Name FROM Account WHERE Id = :acc.ParentId]; // BAD
acc.Description = 'Child of: ' + parent.Name;
}
}
Batch Apex
public class ContactBatchUpdate implements Database.Batchable<SObject> {
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([SELECT Id, Email FROM Contact WHERE Email = null]);
}
public void execute(Database.BatchableContext bc, List<Contact> scope) {
for (Contact c : scope) {
c.Email = 'unknown@example.com';
}
Database.update(scope, false); // partial success allowed
}
public void finish(Database.BatchableContext bc) {
// Send notification or chain next batch
}
}
// Execute: Database.executeBatch(new ContactBatchUpdate(), 200);
Test Class
@IsTest
private class AccountTriggerHandlerTest {
@TestSetup
static void makeData() {
Account parent = new Account(Name = 'Parent Co');
insert parent;
Account child = new Account(Name = 'Child Co', ParentId = parent.Id);
insert child;
}
@IsTest
static void testBulkInsert() {
Account parent = [SELECT Id FROM Account WHERE Name = 'Parent Co' LIMIT 1];
List<Account> children = new List<Account>();
for (Integer i = 0; i < 200; i++) {
children.add(new Account(Name = 'Child ' + i, ParentId = parent.Id));
}
Test.startTest();
insert children;
Test.stopTest();
List<Account> updated = [SELECT Description FROM Account WHERE ParentId = :parent.Id];
System.assert(!updated.isEmpty(), 'Children should have descriptions set');
System.assert(updated[0].Description.startsWith('Child of:'), 'Description format mismatch');
}
}
SOQL Best Practices
// Selective query — use indexed fields in WHERE clause
List<Opportunity> opps = [
SELECT Id, Name, Amount, StageName
FROM Opportunity
WHERE AccountId IN :accountIds // indexed field
AND CloseDate >= :Date.today() // indexed field
ORDER BY CloseDate ASC
LIMIT 200
];
// Relationship query to avoid extra round-trips
List<Account> accounts = [
SELECT Id, Name,
(SELECT Id, LastName, Email FROM Contacts WHERE Email != null)
FROM Account
WHERE Id IN :accountIds
];
Lightning Web Component (Counter Example)
<!-- counterComponent.html -->
<template>
<lightning-card title="Counter">
<div class="slds-p-around_medium">
<p>Count: {count}</p>
<lightning-button label="Increment"
</div>
</lightning-card>
</template>
// counterComponent.js
import { LightningElement, track } from 'lwc';
export default class CounterComponent extends LightningElement {
@track count = 0;
handleIncrement() {
this.count += 1;
}
}
<!-- counterComponent.js-meta.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
</targets>
</LightningComponentBundle>
Documentation
1---2name: salesforce-developer3description: Writes and debugs Apex code, builds Lightning Web Components, optimizes SOQL queries, implements triggers, batch jobs, platform events, and integrations on the Salesforce platform. Use when developing Salesforce applications, customizing CRM workflows, managing governor limits, bulk processing, or setting up Salesforce DX and CI/CD pipelines.4license: MIT5---67# Salesforce Developer89## Core Workflow10111. **Analyze requirements** - Understand business needs, data model, governor limits, scalability122. **Design solution** - Choose declarative vs programmatic, plan bulkification, design integrations133. **Implement** - Write Apex classes, LWC components, SOQL queries with best practices144. **Validate governor limits** - Verify SOQL/DML counts, heap size, and CPU time stay within platform limits before proceeding155. **Test thoroughly** - Write test classes with 90%+ coverage, test bulk scenarios (200-record batches)166. **Deploy** - Use Salesforce DX, scratch orgs, CI/CD for metadata deployment1718## Reference Guide1920Load detailed guidance based on context:2122| Topic | Reference | Load When |23|-------|-----------|-----------|24| Apex Development | `references/apex-development.md` | Classes, triggers, async patterns, batch processing |25| Lightning Web Components | `references/lightning-web-components.md` | LWC framework, component design, events, wire service |26| SOQL/SOSL | `references/soql-sosl.md` | Query optimization, relationships, governor limits |27| Integration Patterns | `references/integration-patterns.md` | REST/SOAP APIs, platform events, external services |28| Deployment & DevOps | `references/deployment-devops.md` | Salesforce DX, CI/CD, scratch orgs, metadata API |2930## Constraints3132### MUST DO33- Bulkify Apex code — collect IDs/records before loops, query/DML outside loops34- Write test classes with minimum 90% code coverage, including bulk scenarios35- Use selective SOQL queries with indexed fields; leverage relationship queries36- Use appropriate async processing (batch, queueable, future) for long-running work37- Implement proper error handling and logging; use `Database.update(scope, false)` for partial success38- Use Salesforce DX for source-driven development and metadata deployment3940### MUST NOT DO41- Execute SOQL/DML inside loops (governor limit violation — see bulkified trigger pattern below)42- Hard-code IDs or credentials in code43- Create recursive triggers without safeguards44- Skip field-level security and sharing rules checks45- Use deprecated Salesforce APIs or components4647## Code Patterns4849### Bulkified Trigger (Correct Pattern)5051```apex52// CORRECT: collect IDs, query once outside the loop53trigger AccountTrigger on Account (before insert, before update) {54 AccountTriggerHandler.handleBeforeInsert(Trigger.new);55}5657public class AccountTriggerHandler {58 public static void handleBeforeInsert(List<Account> newAccounts) {59 Set<Id> parentIds = new Set<Id>();60 for (Account acc : newAccounts) {61 if (acc.ParentId != null) parentIds.add(acc.ParentId);62 }63 Map<Id, Account> parentMap = new Map<Id, Account>(64 [SELECT Id, Name FROM Account WHERE Id IN :parentIds]65 );66 for (Account acc : newAccounts) {67 if (acc.ParentId != null && parentMap.containsKey(acc.ParentId)) {68 acc.Description = 'Child of: ' + parentMap.get(acc.ParentId).Name;69 }70 }71 }72}73```7475```apex76// INCORRECT: SOQL inside loop — governor limit violation77trigger AccountTrigger on Account (before insert) {78 for (Account acc : Trigger.new) {79 Account parent = [SELECT Id, Name FROM Account WHERE Id = :acc.ParentId]; // BAD80 acc.Description = 'Child of: ' + parent.Name;81 }82}83```8485### Batch Apex8687```apex88public class ContactBatchUpdate implements Database.Batchable<SObject> {89 public Database.QueryLocator start(Database.BatchableContext bc) {90 return Database.getQueryLocator([SELECT Id, Email FROM Contact WHERE Email = null]);91 }92 public void execute(Database.BatchableContext bc, List<Contact> scope) {93 for (Contact c : scope) {94 c.Email = 'unknown@example.com';95 }96 Database.update(scope, false); // partial success allowed97 }98 public void finish(Database.BatchableContext bc) {99 // Send notification or chain next batch100 }101}102// Execute: Database.executeBatch(new ContactBatchUpdate(), 200);103```104105### Test Class106107```apex108@IsTest109private class AccountTriggerHandlerTest {110 @TestSetup111 static void makeData() {112 Account parent = new Account(Name = 'Parent Co');113 insert parent;114 Account child = new Account(Name = 'Child Co', ParentId = parent.Id);115 insert child;116 }117118 @IsTest119 static void testBulkInsert() {120 Account parent = [SELECT Id FROM Account WHERE Name = 'Parent Co' LIMIT 1];121 List<Account> children = new List<Account>();122 for (Integer i = 0; i < 200; i++) {123 children.add(new Account(Name = 'Child ' + i, ParentId = parent.Id));124 }125 Test.startTest();126 insert children;127 Test.stopTest();128129 List<Account> updated = [SELECT Description FROM Account WHERE ParentId = :parent.Id];130 System.assert(!updated.isEmpty(), 'Children should have descriptions set');131 System.assert(updated[0].Description.startsWith('Child of:'), 'Description format mismatch');132 }133}134```135136### SOQL Best Practices137138```apex139// Selective query — use indexed fields in WHERE clause140List<Opportunity> opps = [141 SELECT Id, Name, Amount, StageName142 FROM Opportunity143 WHERE AccountId IN :accountIds // indexed field144 AND CloseDate >= :Date.today() // indexed field145 ORDER BY CloseDate ASC146 LIMIT 200147];148149// Relationship query to avoid extra round-trips150List<Account> accounts = [151 SELECT Id, Name,152 (SELECT Id, LastName, Email FROM Contacts WHERE Email != null)153 FROM Account154 WHERE Id IN :accountIds155];156```157158### Lightning Web Component (Counter Example)159160```html161<!-- counterComponent.html -->162<template>163 <lightning-card title="Counter">164 <div class="slds-p-around_medium">165 <p>Count: {count}</p>166 <lightning-button label="Increment" onclick={handleIncrement}></lightning-button>167 </div>168 </lightning-card>169</template>170```171172```javascript173// counterComponent.js174import { LightningElement, track } from 'lwc';175export default class CounterComponent extends LightningElement {176 @track count = 0;177 handleIncrement() {178 this.count += 1;179 }180}181```182183```xml184<!-- counterComponent.js-meta.xml -->185<?xml version="1.0" encoding="UTF-8"?>186<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">187 <apiVersion>59.0</apiVersion>188 <isExposed>true</isExposed>189 <targets>190 <target>lightning__AppPage</target>191 <target>lightning__RecordPage</target>192 </targets>193</LightningComponentBundle>194```195196[Documentation](https://jeffallan.github.io/claude-skills/skills/platform/salesforce-developer/)