salesforce-reliability-patterns
Implement Salesforce reliability patterns including circuit breakers, idempotent upserts, and fallback caching. Use when building fault-tolerant Salesforce integrations, implementing retry strategies, or adding resilience to production Salesforce services. Trigger with phrases like "salesforce reliability", "salesforce circuit breaker", "salesforce idempotent", "salesforce resilience", "salesforce fallback", "salesforce retry".
Best use case
salesforce-reliability-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Implement Salesforce reliability patterns including circuit breakers, idempotent upserts, and fallback caching. Use when building fault-tolerant Salesforce integrations, implementing retry strategies, or adding resilience to production Salesforce services. Trigger with phrases like "salesforce reliability", "salesforce circuit breaker", "salesforce idempotent", "salesforce resilience", "salesforce fallback", "salesforce retry".
Teams using salesforce-reliability-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/salesforce-reliability-patterns/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How salesforce-reliability-patterns Compares
| Feature / Agent | salesforce-reliability-patterns | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Implement Salesforce reliability patterns including circuit breakers, idempotent upserts, and fallback caching. Use when building fault-tolerant Salesforce integrations, implementing retry strategies, or adding resilience to production Salesforce services. Trigger with phrases like "salesforce reliability", "salesforce circuit breaker", "salesforce idempotent", "salesforce resilience", "salesforce fallback", "salesforce retry".
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Marketing
Discover AI agents for marketing workflows, from SEO and content production to campaign research, outreach, and analytics.
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Best AI Agents for Marketing
A curated list of the best AI agents and skills for marketing teams focused on SEO, content systems, outreach, and campaign execution.
SKILL.md Source
# Salesforce Reliability Patterns
## Overview
Production-grade reliability patterns for Salesforce integrations: circuit breakers for API outages, idempotent operations using External IDs, graceful degradation with cached data, and dead letter queues for failed operations.
## Prerequisites
- jsforce connection configured
- Understanding of Salesforce error codes (see `salesforce-common-errors`)
- Redis or database for state management (optional)
- opossum or similar circuit breaker library
## Instructions
### Step 1: Circuit Breaker for Salesforce API
```typescript
import CircuitBreaker from 'opossum';
import { getConnection } from './salesforce/connection';
// Circuit breaker wraps all Salesforce calls
const sfBreaker = new CircuitBreaker(
async (fn: () => Promise<any>) => fn(),
{
timeout: 30000, // SF calls can be slow — 30s timeout
errorThresholdPercentage: 50, // Open circuit at 50% error rate
resetTimeout: 60000, // Try again after 1 minute
volumeThreshold: 10, // Need 10 calls before evaluating
errorFilter: (error: any) => {
// Don't count client errors as circuit-breaking failures
const nonCircuitErrors = ['INVALID_FIELD', 'MALFORMED_QUERY', 'REQUIRED_FIELD_MISSING'];
return nonCircuitErrors.includes(error.errorCode);
},
}
);
sfBreaker.on('open', () => {
console.error('CIRCUIT OPEN: Salesforce API failing — requests will fail fast');
// Alert ops team
});
sfBreaker.on('halfOpen', () => {
console.info('CIRCUIT HALF-OPEN: Testing Salesforce recovery...');
});
sfBreaker.on('close', () => {
console.info('CIRCUIT CLOSED: Salesforce API recovered');
});
// Usage — all SF calls go through the breaker
async function safeSfQuery<T>(soql: string): Promise<T[]> {
return sfBreaker.fire(async () => {
const conn = await getConnection();
const result = await conn.query<T>(soql);
return result.records;
});
}
```
### Step 2: Idempotent Operations with External IDs
```typescript
// Salesforce's upsert with External ID is naturally idempotent
// Same data sent twice = same result (no duplicates)
async function idempotentSync(
objectType: string,
records: Record<string, any>[],
externalIdField: string = 'External_ID__c'
): Promise<{ success: number; failed: number; errors: any[] }> {
const conn = await getConnection();
let success = 0;
let failed = 0;
const errors: any[] = [];
// Process in batches of 200 (sObject Collections limit)
for (let i = 0; i < records.length; i += 200) {
const batch = records.slice(i, i + 200);
const results = await conn.sobject(objectType).upsert(batch, externalIdField);
for (const result of Array.isArray(results) ? results : [results]) {
if (result.success) {
success++;
} else {
failed++;
errors.push(result.errors);
}
}
}
return { success, failed, errors };
}
// Safe to retry — same External_ID__c values will update, not duplicate
await idempotentSync('Account', [
{ External_ID__c: 'EXT-001', Name: 'Acme', Industry: 'Tech' },
{ External_ID__c: 'EXT-002', Name: 'Globex', Industry: 'Manufacturing' },
], 'External_ID__c');
```
### Step 3: Retry with Salesforce-Specific Error Classification
```typescript
const SF_RETRYABLE_ERRORS = [
'REQUEST_LIMIT_EXCEEDED', // API limit — wait and retry
'SERVER_UNAVAILABLE', // SF is down temporarily
'UNABLE_TO_LOCK_ROW', // Record contention
'INVALID_SESSION_ID', // Token expired — re-auth and retry
];
const SF_FATAL_ERRORS = [
'INVALID_FIELD', // Code bug — won't fix itself
'MALFORMED_QUERY', // Code bug
'REQUIRED_FIELD_MISSING', // Data issue
'INVALID_TYPE', // Wrong sObject name
'INSUFFICIENT_ACCESS_OR_READONLY', // Permission issue
];
async function retryableSfCall<T>(
operation: () => Promise<T>,
maxRetries = 3
): Promise<T> {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await operation();
} catch (error: any) {
const errorCode = error.errorCode || error.name;
if (SF_FATAL_ERRORS.includes(errorCode)) {
throw error; // Don't retry — it won't help
}
if (errorCode === 'INVALID_SESSION_ID') {
// Re-authenticate, then retry
await getConnection(); // Forces re-login
continue;
}
if (attempt === maxRetries) throw error;
const delay = 2000 * Math.pow(2, attempt - 1); // 2s, 4s, 8s
console.warn(`Retryable SF error ${errorCode}, attempt ${attempt}/${maxRetries}`);
await new Promise(r => setTimeout(r, delay));
}
}
throw new Error('Unreachable');
}
```
### Step 4: Graceful Degradation with Stale Data
```typescript
import { Redis } from 'ioredis';
const redis = new Redis(process.env.REDIS_URL);
async function queryWithFallback<T>(
soql: string,
cacheKey: string,
cacheTtlSeconds = 300
): Promise<{ data: T[]; stale: boolean }> {
try {
// Try live Salesforce query
const records = await safeSfQuery<T>(soql);
// Update cache for fallback
await redis.set(cacheKey, JSON.stringify(records), 'EX', cacheTtlSeconds * 10);
return { data: records, stale: false };
} catch (error) {
// Salesforce unavailable — serve cached data
const cached = await redis.get(cacheKey);
if (cached) {
console.warn(`SF unavailable, serving stale data for ${cacheKey}`);
return { data: JSON.parse(cached), stale: true };
}
throw new Error(`Salesforce unavailable and no cached data for ${cacheKey}`);
}
}
// Usage
const { data: accounts, stale } = await queryWithFallback<Account>(
"SELECT Id, Name, Industry FROM Account WHERE Industry = 'Technology' LIMIT 50",
'sf:accounts:tech'
);
if (stale) {
// Show warning to user: "Data may be outdated"
}
```
### Step 5: Dead Letter Queue for Failed Operations
```typescript
interface SfDeadLetter {
id: string;
operation: string;
objectType: string;
payload: Record<string, any>;
errorCode: string;
errorMessage: string;
attempts: number;
firstFailure: Date;
lastAttempt: Date;
}
class SalesforceDeadLetterQueue {
async enqueue(entry: Omit<SfDeadLetter, 'id' | 'firstFailure' | 'lastAttempt' | 'attempts'>): Promise<void> {
const dlq: SfDeadLetter = {
...entry,
id: crypto.randomUUID(),
attempts: 1,
firstFailure: new Date(),
lastAttempt: new Date(),
};
await redis.lpush('sf:dlq', JSON.stringify(dlq));
console.error(`DLQ: ${entry.operation} on ${entry.objectType} failed: ${entry.errorCode}`);
}
async reprocess(): Promise<{ processed: number; failed: number }> {
let processed = 0, failed = 0;
let entry: string | null;
while ((entry = await redis.rpop('sf:dlq')) !== null) {
const dlq: SfDeadLetter = JSON.parse(entry);
try {
const conn = await getConnection();
await conn.sobject(dlq.objectType)[dlq.operation](dlq.payload);
processed++;
} catch (error: any) {
dlq.attempts++;
dlq.lastAttempt = new Date();
if (dlq.attempts < 5) {
await redis.lpush('sf:dlq', JSON.stringify(dlq));
} else {
console.error(`DLQ: Giving up on ${dlq.id} after 5 attempts`);
// Move to permanent failure store
}
failed++;
}
}
return { processed, failed };
}
}
```
## Output
- Circuit breaker preventing cascading failures
- Idempotent upserts using External IDs
- Error classification (retryable vs fatal)
- Graceful degradation with stale cache data
- Dead letter queue for failed operations
## Error Handling
| Issue | Cause | Solution |
|-------|-------|----------|
| Circuit stays open | SF outage or wrong threshold | Check status.salesforce.com; tune thresholds |
| Duplicate records | Not using External ID upsert | Add External_ID__c field, use upsert |
| DLQ growing | Persistent error (e.g., permission) | Check error codes — may need fix, not retry |
| Stale cache too old | Long SF outage | Set max stale age, show user warning |
## Resources
- [Circuit Breaker Pattern](https://martinfowler.com/bliki/CircuitBreaker.html)
- [Opossum Documentation](https://nodeshift.dev/opossum/)
- [External ID Fields](https://help.salesforce.com/s/articleView?id=sf.fields_about_external_ids.htm)
- [Salesforce Error Codes](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/errorcodes.htm)
## Next Steps
For policy enforcement, see `salesforce-policy-guardrails`.Related Skills
workhuman-sdk-patterns
Workhuman sdk patterns for employee recognition and rewards API. Use when integrating Workhuman Social Recognition, or building recognition workflows with HRIS systems. Trigger: "workhuman sdk patterns".
wispr-sdk-patterns
Wispr Flow sdk patterns for voice-to-text API integration. Use when integrating Wispr Flow dictation, WebSocket streaming, or building voice-powered applications. Trigger: "wispr sdk patterns".
windsurf-sdk-patterns
Apply production-ready Windsurf workspace configuration and Cascade interaction patterns. Use when configuring .windsurfrules, workspace rules, MCP servers, or establishing team coding standards for Windsurf AI. Trigger with phrases like "windsurf patterns", "windsurf best practices", "windsurf config patterns", "windsurfrules", "windsurf workspace".
windsurf-reliability-patterns
Implement reliable Cascade workflows with checkpoints, rollback, and incremental editing. Use when building fault-tolerant AI coding workflows, preventing Cascade from breaking builds, or establishing safe practices for multi-file AI edits. Trigger with phrases like "windsurf reliability", "cascade safety", "windsurf rollback", "cascade checkpoint", "safe cascade workflow".
webflow-sdk-patterns
Apply production-ready Webflow SDK patterns — singleton client, typed error handling, pagination helpers, and raw response access for the webflow-api package. Use when implementing Webflow integrations, refactoring SDK usage, or establishing team coding standards. Trigger with phrases like "webflow SDK patterns", "webflow best practices", "webflow code patterns", "idiomatic webflow", "webflow typescript".
vercel-sdk-patterns
Production-ready Vercel REST API patterns with typed fetch wrappers and error handling. Use when integrating with the Vercel API programmatically, building deployment tools, or establishing team coding standards for Vercel API calls. Trigger with phrases like "vercel SDK patterns", "vercel API wrapper", "vercel REST API client", "vercel best practices", "idiomatic vercel API".
vercel-reliability-patterns
Implement reliability patterns for Vercel deployments including circuit breakers, retry logic, and graceful degradation. Use when building fault-tolerant serverless functions, implementing retry strategies, or adding resilience to production Vercel services. Trigger with phrases like "vercel reliability", "vercel circuit breaker", "vercel resilience", "vercel fallback", "vercel graceful degradation".
veeva-sdk-patterns
Veeva Vault sdk patterns for REST API and clinical operations. Use when working with Veeva Vault document management and CRM. Trigger: "veeva sdk patterns".
vastai-sdk-patterns
Apply production-ready Vast.ai SDK patterns for Python and REST API. Use when implementing Vast.ai integrations, refactoring SDK usage, or establishing coding standards for GPU cloud operations. Trigger with phrases like "vastai SDK patterns", "vastai best practices", "vastai code patterns", "idiomatic vastai".
twinmind-sdk-patterns
Apply production-ready TwinMind SDK patterns for TypeScript and Python. Use when implementing TwinMind integrations, refactoring API usage, or establishing team coding standards for meeting AI integration. Trigger with phrases like "twinmind SDK patterns", "twinmind best practices", "twinmind code patterns", "idiomatic twinmind".
together-sdk-patterns
Together AI sdk patterns for inference, fine-tuning, and model deployment. Use when working with Together AI's OpenAI-compatible API. Trigger: "together sdk patterns".
techsmith-sdk-patterns
TechSmith sdk patterns for Snagit COM API and Camtasia automation. Use when working with TechSmith screen capture and video editing automation. Trigger: "techsmith sdk patterns".