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: MIT5metadata:6 source: https://skillmd.com/skills/jeffallan/salesforce-developer7 author: https://github.com/Jeffallan8 version: "1.1.0"9 domain: platform10 triggers: Salesforce, Apex, Lightning Web Components, LWC, SOQL, SOSL, Visualforce, Salesforce DX, governor limits, triggers, platform events, CRM integration, Sales Cloud, Service Cloud11 role: expert12 scope: implementation13 output-format: code14 related-skills: api-designer, java-architect, cloud-architect, devops-engineer15---1617# Salesforce Developer1819## Core Workflow20211. **Analyze requirements** - Understand business needs, data model, governor limits, scalability222. **Design solution** - Choose declarative vs programmatic, plan bulkification, design integrations233. **Implement** - Write Apex classes, LWC components, SOQL queries with best practices244. **Validate governor limits** - Verify SOQL/DML counts, heap size, and CPU time stay within platform limits before proceeding255. **Test thoroughly** - Write test classes with 90%+ coverage, test bulk scenarios (200-record batches)266. **Deploy** - Use Salesforce DX, scratch orgs, CI/CD for metadata deployment2728## Reference Guide2930Load detailed guidance based on context:3132| Topic | Reference | Load When |33|-------|-----------|-----------|34| Apex Development | `references/apex-development.md` | Classes, triggers, async patterns, batch processing |35| Lightning Web Components | `references/lightning-web-components.md` | LWC framework, component design, events, wire service |36| SOQL/SOSL | `references/soql-sosl.md` | Query optimization, relationships, governor limits |37| Integration Patterns | `references/integration-patterns.md` | REST/SOAP APIs, platform events, external services |38| Deployment & DevOps | `references/deployment-devops.md` | Salesforce DX, CI/CD, scratch orgs, metadata API |3940## Constraints4142### MUST DO43- Bulkify Apex code — collect IDs/records before loops, query/DML outside loops44- Write test classes with minimum 90% code coverage, including bulk scenarios45- Use selective SOQL queries with indexed fields; leverage relationship queries46- Use appropriate async processing (batch, queueable, future) for long-running work47- Implement proper error handling and logging; use `Database.update(scope, false)` for partial success48- Use Salesforce DX for source-driven development and metadata deployment4950### MUST NOT DO51- Execute SOQL/DML inside loops (governor limit violation — see bulkified trigger pattern below)52- Hard-code IDs or credentials in code53- Create recursive triggers without safeguards54- Skip field-level security and sharing rules checks55- Use deprecated Salesforce APIs or components5657## Code Patterns5859### Bulkified Trigger (Correct Pattern)6061```apex62// CORRECT: collect IDs, query once outside the loop63trigger AccountTrigger on Account (before insert, before update) {64 AccountTriggerHandler.handleBeforeInsert(Trigger.new);65}6667public class AccountTriggerHandler {68 public static void handleBeforeInsert(List<Account> newAccounts) {69 Set<Id> parentIds = new Set<Id>();70 for (Account acc : newAccounts) {71 if (acc.ParentId != null) parentIds.add(acc.ParentId);72 }73 Map<Id, Account> parentMap = new Map<Id, Account>(74 [SELECT Id, Name FROM Account WHERE Id IN :parentIds]75 );76 for (Account acc : newAccounts) {77 if (acc.ParentId != null && parentMap.containsKey(acc.ParentId)) {78 acc.Description = 'Child of: ' + parentMap.get(acc.ParentId).Name;79 }80 }81 }82}83```8485```apex86// INCORRECT: SOQL inside loop — governor limit violation87trigger AccountTrigger on Account (before insert) {88 for (Account acc : Trigger.new) {89 Account parent = [SELECT Id, Name FROM Account WHERE Id = :acc.ParentId]; // BAD90 acc.Description = 'Child of: ' + parent.Name;91 }92}93```9495### Batch Apex9697```apex98public class ContactBatchUpdate implements Database.Batchable<SObject> {99 public Database.QueryLocator start(Database.BatchableContext bc) {100 return Database.getQueryLocator([SELECT Id, Email FROM Contact WHERE Email = null]);101 }102 public void execute(Database.BatchableContext bc, List<Contact> scope) {103 for (Contact c : scope) {104 c.Email = 'unknown@example.com';105 }106 Database.update(scope, false); // partial success allowed107 }108 public void finish(Database.BatchableContext bc) {109 // Send notification or chain next batch110 }111}112// Execute: Database.executeBatch(new ContactBatchUpdate(), 200);113```114115### Test Class116117```apex118@IsTest119private class AccountTriggerHandlerTest {120 @TestSetup121 static void makeData() {122 Account parent = new Account(Name = 'Parent Co');123 insert parent;124 Account child = new Account(Name = 'Child Co', ParentId = parent.Id);125 insert child;126 }127128 @IsTest129 static void testBulkInsert() {130 Account parent = [SELECT Id FROM Account WHERE Name = 'Parent Co' LIMIT 1];131 List<Account> children = new List<Account>();132 for (Integer i = 0; i < 200; i++) {133 children.add(new Account(Name = 'Child ' + i, ParentId = parent.Id));134 }135 Test.startTest();136 insert children;137 Test.stopTest();138139 List<Account> updated = [SELECT Description FROM Account WHERE ParentId = :parent.Id];140 System.assert(!updated.isEmpty(), 'Children should have descriptions set');141 System.assert(updated[0].Description.startsWith('Child of:'), 'Description format mismatch');142 }143}144```145146### SOQL Best Practices147148```apex149// Selective query — use indexed fields in WHERE clause150List<Opportunity> opps = [151 SELECT Id, Name, Amount, StageName152 FROM Opportunity153 WHERE AccountId IN :accountIds // indexed field154 AND CloseDate >= :Date.today() // indexed field155 ORDER BY CloseDate ASC156 LIMIT 200157];158159// Relationship query to avoid extra round-trips160List<Account> accounts = [161 SELECT Id, Name,162 (SELECT Id, LastName, Email FROM Contacts WHERE Email != null)163 FROM Account164 WHERE Id IN :accountIds165];166```167168### Lightning Web Component (Counter Example)169170```html171<!-- counterComponent.html -->172<template>173 <lightning-card title="Counter">174 <div class="slds-p-around_medium">175 <p>Count: {count}</p>176 <lightning-button label="Increment" onclick={handleIncrement}></lightning-button>177 </div>178 </lightning-card>179</template>180```181182```javascript183// counterComponent.js184import { LightningElement, track } from 'lwc';185export default class CounterComponent extends LightningElement {186 @track count = 0;187 handleIncrement() {188 this.count += 1;189 }190}191```192193```xml194<!-- counterComponent.js-meta.xml -->195<?xml version="1.0" encoding="UTF-8"?>196<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">197 <apiVersion>59.0</apiVersion>198 <isExposed>true</isExposed>199 <targets>200 <target>lightning__AppPage</target>201 <target>lightning__RecordPage</target>202 </targets>203</LightningComponentBundle>204```205206[Documentation](https://jeffallan.github.io/claude-skills/skills/platform/salesforce-developer/)