grzmol/vibe-force/sf-fflib-operations

Claude Code and agent skill by grzmol/vibe-force

Trust tier 3
  • community
  • ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Source check pending

Checking that the SKILL.md file is still in the repository.

Covers running fflib Apex Enterprise Patterns in a real delivery pipeline - trigger inventory and one-trigger-per-object dispatch, bypass and kill-switch design with custom permissions and custom metadata, feature flags that swap Application factory bindings, Queueable with Finalizer and Batch runners that call services with per-chunk Unit of Work commits, platform-event publishing and subscriber domains, callout ordering around commitWork, large-data-volume tuning, structured logging and correlation ids, packaging and deployment ordering for fflib-apex-mocks and fflib-apex-common, Code Analyzer rules that misfire on fflib, PR review checklists and the fflib version-upgrade runbook. Use this skill when auditing triggers in an fflib org, adding a bypass switch, running fflib code from Batch or Queueable, packaging or upgrading fflib, tuning Code Analyzer for fflib, or reviewing an fflib pull request.

Install

npx vskill@latest install grzmol/vibe-force/sf-fflib-operations

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

The same SKILL.md was published earlier as majiayu000/claude-skill-registry/sf-fflib-operations.

fflib Operations

Everything around the fflib write path: dispatch inventory, switches, async, bulk, observability, packaging, analysis and upgrades. The layer semantics themselves are in skill sf-fflib-domain-service-uow; the factories in skill sf-fflib-foundations.

Grounded in apex-enterprise-patterns/fflib-apex-common master @ dab59777bac37f6b8a3cc2871fcf5df8d37764b4, fflib-apex-common-samplecode master @ 4657d63, and fflib-apex-mocks master (raw file reads, see References).

When to use

SituationUse this skill
Auditing which objects have triggers and which are fflib-dispatchedYes
Adding an admin-visible bypass for a data load or an incidentYes
Running an fflib service from Batch, Queueable or SchedulableYes
Packaging fflib as an unlocked package, or bumping the fflib versionYes
Tuning code-analyzer.yml because PMD flags every selectorYes
Writing a domain, service or Unit of WorkNo - skill sf-fflib-domain-service-uow
Writing selector queriesNo - skill sf-fflib-selector-layer
Writing the testsNo - skill sf-fflib-testing

Quick reference

ConcernMechanismWhere it lives
Trigger dispatchfflib_SObjectDomain.triggerHandler(X.class)One trigger per object
Per-user / per-integration bypassCustom permission read with FeatureManagement.checkPermissionChecked in one BypassService
Admin-tunable, deployable toggleCustom metadata __mdt read with getInstance / getAllNo SOQL cost
Implementation swapApplication.Service binding chosen from custom metadataFactory construction
Async service runQueueable + System.Finalizer, or Batch with a selector QueryLocatorreferences/async-and-bulk.md
Reliable event emissionuow.registerPublishAfterSuccessTransaction(...)Service
Deployment orderingapex-mocks, then apex-common, then app codereferences/packaging-and-deployment.md

Core patterns

1. Trigger inventory and dispatch strategy

An fflib org has exactly one trigger per object, and that trigger does nothing but dispatch. Inventory the org before changing anything:

bash
sf data query --target-org vf-dev --use-tooling-api \
--query "SELECT Name, TableEnumOrId, Status, ApiVersion FROM ApexTrigger ORDER BY TableEnumOrId"
FindingAction
Two triggers on one objectMerge into one; a second trigger re-enters the dispatcher with a different record set and breaks stateful domains
Trigger with inline logicMove the body into a domain override, leave the dispatch line
Legacy handler framework alongside fflibMigrate object by object; during the transition, the single trigger calls the legacy handler and fflib_SObjectDomain.triggerHandler, in that order, so ordering stays deterministic
Record-triggered Flow doing the same workDecide one owner per rule; Flows and Apex triggers interleave by order of execution, not by intent (skill sf-flow-automation)
2. Bypass and kill switches

fflib_SObjectDomain.getTriggerEvent(...) is transaction-scoped Apex state - useful inside a job, useless as an operational switch. Operational switches need a single, testable read point:

apex
public with sharing class BypassService
{
private static Map<String, Boolean> cache = new Map<String, Boolean>();
public static Boolean isBypassed(SObjectType objectType)
{
return isBypassed('Trigger_' + objectType.getDescribe().getName());
}
public static Boolean isBypassed(String featureName)
{
if (cache.containsKey(featureName)) { return cache.get(featureName); }
Bypass__mdt setting = Bypass__mdt.getInstance(featureName); // no SOQL cost
Boolean bypassed = setting != null
&& (setting.Disabled__c
|| (String.isNotBlank(setting.CustomPermission__c)
&& FeatureManagement.checkPermission(setting.CustomPermission__c)));
cache.put(featureName, bypassed);
return bypassed;
}
@TestVisible
private static void setBypass(String name, Boolean value) { cache.put(name, value); }
}
apex
public override void onAfterUpdate(Map<Id, SObject> existingRecords)
{
if (BypassService.isBypassed(Opportunity.SObjectType)) { return; }
// ...
}

__mdt.getInstance(...) and getAll() read from the metadata cache and do not consume SOQL queries; only the first 255 characters of any field are returned (Custom metadata types methods). Full implementations with tests, plus the data-load bypass used with sf data import bulk (skill sf-data-management): references/bypass-and-feature-flags.md.

3. Feature flags that swap factory bindings

fflib makes a feature flag a binding change rather than an if scattered through the code:

apex
public class Application
{
public static final fflib_Application.ServiceFactory Service =
new fflib_Application.ServiceFactory(serviceBindings());
private static Map<Type, Type> serviceBindings()
{
Boolean useV2 = !BypassService.isBypassed('Feature_NewPricing');
return new Map<Type, Type>{
IProjectsService.class => ProjectsServiceImpl.class,
IPricingService.class => useV2 ? PricingServiceV2Impl.class
: PricingServiceV1Impl.class
};
}
}

Both implementations stay deployed and tested; the switch is metadata. Rollback is a metadata deploy, not a code revert.

4. Async runners

Rules that do not change:

RuleReason
The async class is a shell; it calls a serviceBusiness logic stays testable synchronously
One Unit of Work per chunk / per Queueable executionEach is its own transaction; a UoW cannot cross them
Never pass a UoW or a domain instance into a QueueableSObject references have no committed context in the next transaction
Idempotency key on every chunkBatch chunks can be retried by the platform
Finalizer for failure handling and retryRuns in its own transaction, so it can call out after the job did DML
apex
public with sharing class ProjectSyncQueueable
implements Queueable, Database.AllowsCallouts, System.Finalizer
{
private final Set<Id> projectIds;
private final String correlationId;
public ProjectSyncQueueable(Set<Id> projectIds, String correlationId)
{
this.projectIds = projectIds;
this.correlationId = correlationId;
}
public void execute(QueueableContext context)
{
System.attachFinalizer(this); // exactly one finalizer per job
ProjectSyncService.sync(projectIds, correlationId);
}
public void execute(FinalizerContext context)
{
if (context.getResult() == ParentJobResult.SUCCESS) { return; }
LoggingService.recordAsyncFailure(
correlationId, context.getAsyncApexJobId(), context.getException());
}
}

System.attachFinalizer accepts one finalizer per Queueable execution; the finalizer runs in a separate Apex and database transaction, and a failing job can be re-enqueued from a finalizer at most five consecutive times (Transaction finalizers). Batch, chunking and idempotency keys: references/async-and-bulk.md and skill sf-async-apex-patterns.

5. Platform events and integration flows

Publish through the Unit of Work so emission is tied to commit outcome, and subscribe with an ordinary fflib domain over the __e records:

apex
trigger ProjectEvents on ProjectEvent__e (after insert)
{
fflib_SObjectDomain.triggerHandler(ProjectEvents.class);
}
apex
public inherited sharing class ProjectEvents extends fflib_SObjectDomain
{
public ProjectEvents(List<ProjectEvent__e> records)
{
super(records, ProjectEvent__e.SObjectType);
// The Automated Process user has no CRUD on the related objects
Configuration.disableTriggerCRUDSecurity();
}
public override void onAfterInsert()
{
Set<Id> opportunityIds = new Set<Id>();
for (ProjectEvent__e event : (List<ProjectEvent__e>) Records)
{
if (event.Action__c == 'ProjectCreated')
{
opportunityIds.add((Id) event.Opportunity__c); // event field is Text
}
}
if (opportunityIds.isEmpty()) { return; }
DeliveryHandoffService.handOff(opportunityIds);
}
public class Constructor implements fflib_SObjectDomain.IConstructable
{
public fflib_SObjectDomain construct(List<SObject> records)
{
return new ProjectEvents((List<ProjectEvent__e>) records);
}
}
}

Use the two-argument super(records, SObjectType) constructor: an empty __e batch cannot infer its type. Replay, retry and high-volume subscriber concerns: skill sf-integration-patterns.

6. Callouts and commitWork()

Apex forbids a callout after uncommitted DML in the same transaction. commitWork() is DML, so:

OrderVerdict
Callout, then register, then commitWork()Correct
commitWork(), then callout in the same transactionThrows You have uncommitted work pending
commitWork(), then callout from a Queueable or a FinalizerCorrect - separate transaction
Callout inside an IDoWork registered with registerWorkWrong - doWork() runs inside the commit, after DML
apex
public void pushToDelivery(Set<Id> projectIds)
{
DeliveryResponse response = DeliveryGateway.post(buildPayload(projectIds)); // callout first
fflib_ISObjectUnitOfWork uow = Application.UnitOfWork.newInstance();
for (Project__c project : ProjectsSelector.newInstance().selectSObjectsById(projectIds))
{
project.ExternalId__c = response.idByProject.get(project.Id);
uow.registerDirty(project, new List<SObjectField>{ Project__c.ExternalId__c });
}
uow.commitWork(); // DML last
}

Mocking the gateway: skill sf-fflib-testing; named credentials and retry: skill sf-integration-patterns.

7. Large data volumes
CostMeasurementMitigation
Domain instantiation per chunkfflib_SObjectDomain copies the record list and describes the SObject once per constructionOne domain instance per chunk, never per record
Selector field list breadthHeap grows with fields x rowsNarrow selector methods for bulk jobs (skill sf-fflib-selector-layer)
UoW DML statements1 savepoint + 1 per non-empty type per operationOne commitWork() per chunk
Relationship resolutionIterates registered relationships per typeRegister parents and children in one pass
Trigger re-entry during commitEach UoW insert fires the target object's triggerBypass the sub-object's domain for the job when the job already owns that logic

Batch scope for fflib work starts at 200 and comes down only with evidence; profile with a debug log before changing it (skill sf-debugging-logs). Limit arithmetic: skill sf-governor-limits; query shape: skill sf-soql-sosl-optimization.

Bypassing the framework for a bulk job is legitimate when the job is a pure data movement with no business rules - document the decision in the job class header and keep the bypass narrow.

8. Observability
apex
fflib_ISObjectUnitOfWork uow = Application.UnitOfWork.newInstance();
String correlationId = LoggingService.newCorrelationId();

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Extension points

  • hookPre/post lifecycle hooks

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/grzmol/vibe-force/sf-fflib-operations/badge)](https://verified-skill.com/skills/grzmol/vibe-force/sf-fflib-operations)

Something wrong with this skill or its page? Tell us.