grzmol/vibe-force/sf-fflib-foundations

Claude Code and agent skill by grzmol/vibe-force

Trust tier 3
  • community
Source check pending

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

Covers the fflib Apex Enterprise Patterns stack (fflib-apex-common, fflib-apex-mocks) - the four-layer Service/Domain/Selector/Unit of Work separation, the Application factory class with its SObject-to-class binding maps, interface plus implementation naming, installation by vendoring or git submodule, sfdx-project.json and .forceignore wiring for a dedicated fflib package directory, the setMock injection points used by unit tests, PMD/Code Analyzer ruleset scoping for fflib code, and an honest decision table for when plain trigger handlers plus service classes are the better answer. Use it when a project adds or removes fflib, when creating or editing Application.cls, when deciding whether a requirement deserves a Service/Domain/Selector split, when migrating legacy Apex to Apex Enterprise Patterns, or when fflib_Application.DeveloperException, "No implementation registered for service interface", or "Selector class not found for SObjectType" appears in a log.

Install

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

SKILL.md

The same SKILL.md was published earlier as grzmol/vibe-force/sf-fflib-foundations.

fflib Foundations: Apex Enterprise Patterns

Source of truth for every signature below: apex-enterprise-patterns/fflib-apex-common @ master commit dab5977 (sfdx-source/apex-common/main/classes/*.cls), fflib-apex-mocks @ master commit d81e9e1, fflib-apex-common-samplecode @ master commit 4657d63. Anything not read from those files this session is marked [unverified].

When to use

SituationUse this skill
Adding fflib to a repo for the first timeYes - references/install-and-layout.md
Writing or fixing Application.clsYes - references/application-factory.md
Choosing fflib vs trigger handler + service classYes - references/fflib-vs-plain-apex.md
Looking up what an fflib_* class doesYes - references/class-catalogue.md
Writing a selector or a querySkill sf-fflib-selector-layer
Writing a domain, service, or Unit of WorkSkill sf-fflib-domain-service-uow
Mocking, stubbing, verifying with ApexMocksSkill sf-fflib-testing
Trigger wiring, batch entry points, day-2 operationsSkill sf-fflib-operations
Plain Apex idioms, no fflib in the repoSkill sf-apex-development

Decision table: does fflib earn its keep here?

SignalfflibPlain trigger handler + service classes
SObjects with non-trivial write logic> 5<= 5
Apex classes in the package> 40< 40
Multiple entry points per SObject (trigger, LWC, REST, batch, Flow invocable)YesOne or two
Unit tests must run without DML (Set<Id> + stubs)RequiredNice to have
Second-generation packaging with a shared base libraryYesNo
Team has used Apex Enterprise Patterns beforeYesNo, and no budget to learn
Automation mostly Flow / Record-Triggered FlowNoYes - see skill sf-flow-automation
Org is a single-admin org with < 10 Apex classesNoYes

Two or more "plain" answers means do not adopt fflib. The library costs roughly 3 extra files per SObject (interface, implementation, mock registration) and a permanent onboarding tax. See references/fflib-vs-plain-apex.md for the same requirement implemented both ways.

Core patterns

1. The four layers and the dependency rules
Entry points triggers, LWC @AuraEnabled controllers, REST resources,
Batchable/Queueable, InvocableMethod
| (only calls)
Service layer coarse-grained, bulkified, transaction boundary, owns the UnitOfWork
|
Domain layer record-oriented behaviour + validation for one SObjectType
|
Selector layer all SOQL
|
Unit of Work all DML, ordered by SObjectType dependency

Enforceable rules, in priority order:

RuleWhy
Only the Service layer calls commitWork()one transaction boundary per use case
Selectors never call services or domainsthey would become untestable and recursive
Domains never issue SOQL or DML directlythey get records in, register work out
Entry points contain no business logic, only marshallinglets Flow/LWC/REST share behaviour
Every layer is reached through Application.*, never new Impl() in product codemock injection
Service methods take and return bulk shapes (Set<Id>, List<SObject>)see skill sf-governor-limits
2. Application.cls is the only wiring file

One class per package, four static finals. Verified shape from fflib-apex-common-samplecode/.../main/classes/Application.cls:

apex
public class Application {
// SObjectTypes in dependency order: parents before children.
public static final fflib_Application.UnitOfWorkFactory UnitOfWork =
new fflib_Application.UnitOfWorkFactory(
new List<SObjectType> {
Account.SObjectType,
Opportunity.SObjectType,
OpportunityLineItem.SObjectType,
Invoice__c.SObjectType,
InvoiceLine__c.SObjectType });
// Interface -> implementing class.
public static final fflib_Application.ServiceFactory Service =
new fflib_Application.ServiceFactory(
new Map<Type, Type> {
IAccountsService.class => AccountsServiceImpl.class,
IOpportunitiesService.class => OpportunitiesServiceImpl.class });
// SObjectType -> selector class.
public static final fflib_Application.SelectorFactory Selector =
new fflib_Application.SelectorFactory(
new Map<SObjectType, Type> {
Account.SObjectType => AccountsSelector.class,
Opportunity.SObjectType => OpportunitiesSelector.class });
// SObjectType -> domain constructor class.
public static final fflib_Application.DomainFactory Domain =
new fflib_Application.DomainFactory(
Application.Selector,
new Map<SObjectType, Type> {
Account.SObjectType => Accounts.Constructor.class,
Opportunity.SObjectType => Opportunities.Constructor.class });
}

newInstance resolves the registered Type and calls Type.newInstance(), so every registered class needs a public zero-argument constructor. Unregistered lookups throw fflib_Application.DeveloperException with No implementation registered for service interface X or Selector class not found for SObjectType X (fflib_Application.cls). Full binding tables, the UserModeDML factory subclass and the common wiring mistakes are in references/application-factory.md.

3. Naming and file layout

The samplecode conventions, verified against its class paths:

LayerInterfaceImplementationCaller writes
ServiceIAccountsServiceAccountsServiceImplAccountsService.updateOpportunityActivity(ids) (static facade)
DomainIAccountsAccounts (+ inner Constructor)(IAccounts) Application.Domain.newInstance(ids)
SelectorIAccountsSelector extends fflib_ISObjectSelectorAccountsSelectorAccountsSelector.newInstance()
Unit of Workfflib_ISObjectUnitOfWorkfflib_SObjectUnitOfWorkApplication.UnitOfWork.newInstance()

The service layer is three files: a with sharing static facade (AccountsService), the interface (IAccountsService), and the implementation (AccountsServiceImpl). The facade exists so callers keep static call syntax while the factory still controls instantiation:

apex
public with sharing class AccountsService {
public static void updateOpportunityActivity(Set<Id> accountIds) {
service().updateOpportunityActivity(accountIds);
}
private static IAccountsService service() {
return (IAccountsService) Application.Service.newInstance(IAccountsService.class);
}
}

Directory layout inside a package directory (samplecode uses exactly these folder names):

force-app/main/default/classes/
Application.cls
service/ AccountsService.cls IAccountsService.cls AccountsServiceImpl.cls
domains/ Accounts.cls IAccounts.cls
selectors/ AccountsSelector.cls IAccountsSelector.cls
triggerHandlers/ AccountsTriggerHandler.cls
controllers/ batchjobs/ restapis/
4. Installation: vendor, submodule, or deploy

fflib-apex-common @ master publishes no unlocked-package version id and no GitHub release; the repo has zero releases and its README advertises only a GitHub-deploy button. Any 04t... install id for these libraries is [unverified] - do not put one in a script.

bash
# Option A (recommended): vendor into a dedicated package directory, pinned to a commit.
git clone https://github.com/apex-enterprise-patterns/fflib-apex-mocks.git /tmp/fflib-mocks
git -C /tmp/fflib-mocks checkout d81e9e1
mkdir -p fflib/main/default
cp -R /tmp/fflib-mocks/sfdx-source/apex-mocks/main/classes fflib/main/default/classes
# then fflib-apex-common on top of the same directory
# Deploy order matters only if your own tests reference ApexMocks: mocks first, then common.
sf project deploy start --source-dir fflib --target-org vf-dev --wait 20

fflib-apex-common's current README states "Dependencies: None for deployment or for running this library's Apex tests"; its docs/changelog.md still carries the September 2014 note that ApexMocks "must be deployed to the org before deploying this library". The README reflects master - deploy mocks first anyway, it is free and removes the ambiguity. Submodule and upgrade procedures: references/install-and-layout.md. Packaging consequences: skills sf-project-structure and sf-packaging-release.

5. Mock injection points

setMock on every factory is protected and @TestVisible, so it compiles only from test context (fflib_Application.cls).

CallArgument type
Application.UnitOfWork.setMock(uowMock)fflib_ISObjectUnitOfWork
Application.Service.setMock(IAccountsService.class, serviceMock)Type, Object
Application.Selector.setMock(selectorMock)fflib_ISObjectSelector - requires sObjectType() stubbed
Application.Selector.setMock(Account.SObjectType, selectorMock)SObjectType, fflib_ISObjectSelector
Application.Domain.setMock(domainMock)fflib_ISObjectDomain (uses sObjectType()) or fflib_IDomain (uses getType())
Application.Domain.setMock(Account.SObjectType, domainMock)SObjectType, fflib_ISObjectDomain

The single-argument selector and domain overloads call sObjectType() on the mock; if it is not stubbed the mock returns null and registration silently binds to null. fflib logs an INFO System.debug in that path. Prefer the two-argument overload. Detail: skill sf-fflib-testing.

6. Incremental migration from legacy Apex (strangler)
StepActionOld code
1Deploy fflib-apex-mocks + fflib-apex-common, add empty Application.clsuntouched
2Extract queries of the busiest SObject into XSelector, register itlegacy class calls XSelector.newInstance().selectById(ids)
3Introduce fflib_ISObjectUnitOfWork in the one method with the most DML statementsDML removed from legacy class
4Create IXService/XServiceImpl, move the legacy method body in verbatimlegacy public method becomes a one-line delegator
5Introduce the Domain class only once two callers need the same record-level rule-
6Convert the trigger last, after Service and Selector exist-

Keep the legacy class as a thin delegator until every caller is migrated, then delete it in the same release; do not leave two ways to do the same thing. Never mix a legacy [SELECT ...] and a selector for the same SObject in one class.

7. Static analysis and performance characteristics

fflib's own source suppresses PMD rules (fflib_SObjectSelector.cls header suppresses PMD.CyclomaticComplexity, PMD.ExcessivePublicCount, PMD.ApexDoc and more), so the library deploys clean only if your analyzer run excludes vendored paths. In your own fflib code expect:

RuleTriggerHandling
ApexCRUDViolationDatabase.query(qf.toSOQL()) - PMD cannot see the WITH USER_MODE that toSOQL() emitsconfigure readAuthMethodPattern for your selector base, or scope the rule out of selectors/
ApexSOQLInjectiondynamic query string built by fflib_QueryFactorysame; use Database.queryWithBinds for user input
ApexSharingViolationsAccountsServiceImpl without a sharing keywordalways declare with sharing or inherited sharing
ApexDoc, ApexUnitTestClassShouldHaveAssertsgenerated interfaces, Impl classeskeep as advisory, not gating

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

Repository stars
3
7-day trend score
7

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

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-foundations/badge)](https://verified-skill.com/skills/grzmol/vibe-force/sf-fflib-foundations)

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