sf-fflib-foundations

Implements the fflib Apex Enterprise Patterns four-layer architecture and Application factory wiring in Salesforce projects.

2|Updated Sep 12, 2026
One-click install
npx skills add https://github.com/grzmol/vibe-force --skill sf-fflib-foundations-grzmol
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sf-fflib-foundations
Source: https://github.com/grzmol/vibe-force/tree/main/skills/sf-fflib-foundations
Command: npx skills add https://github.com/grzmol/vibe-force --skill sf-fflib-foundations-grzmol

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Adopting the fflib Apex Enterprise Patterns stack (fflib-apex-common, fflib-apex-mocks) involves many failure-prone decisions: whether the library earns its keep, how to vendor it without a published package version, how to wire Application.cls correctly, and how to diagnose DeveloperException errors when factory bindings are missing. This Skill provides verified, commit-pinned guidance for all of these. ## Core Features & Use Cases - Adoption decision support: A decision table comparing fflib against plain trigger handlers plus service classes, with the same requirement implemented both ways so the cost is visible. - Application factory wiring: Complete reference Application.cls with UnitOfWork, Service, Selector, and Domain factory registrations, the setMock injection matrix, and a wiring-mistake troubleshooting table. - Installation and layout: Vendoring and git submodule procedures pinned to specific commits, sfdx-project.json and .forceignore configuration, and coverage implications of vendoring library tests. - Use Case: A team adding fflib to an existing Salesforce repo uses this Skill to vendor fflib-apex-mocks and fflib-apex-common at pinned commits, create Application.cls with correctly ordered SObjectType bindings, and verify the wiring with anonymous Apex assertions. ## Quick Start Ask the assistant to add fflib to the project and create an Application.cls registering the Account selector, service, and domain layers.

Frequently Asked Questions about sf-fflib-foundations

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I install fflib-apex-common in a Salesforce DX project?

Vendor the library by cloning fflib-apex-mocks and fflib-apex-common at pinned commits and copying their classes into a dedicated fflib package directory listed in sfdx-project.json. Neither library publishes an unlocked package version id, so any 04t install id is unverified. Also copy the custom labels, or fflib_SecurityUtils fails to compile.

When should I use fflib versus plain trigger handlers and service classes?

Adopt fflib when you have more than five SObjects with write logic, over 40 Apex classes, multiple entry points per behavior, and a policy of DML-free unit tests. Two or more answers favoring plain Apex in the decision table means the library's indirection and onboarding cost are not justified.

Why does fflib throw 'No implementation registered for service interface'?

This DeveloperException means the service interface is missing from the Application.Service map, or the facade class was registered instead of the interface. Register the pair as IServiceName.class mapped to ServiceNameImpl.class in Application.cls.

How do I mock fflib selectors and Unit of Work in Apex tests?

Use Application.UnitOfWork.setMock, Application.Service.setMock, and Application.Selector.setMock from test context, since setMock is protected and TestVisible. Prefer the two-argument selector overload with an explicit SObjectType, because the single-argument version requires sObjectType() to be stubbed first.

Does vendoring fflib affect org code coverage?

Yes. The two libraries add roughly 5,600 lines of Apex, so deploying only the main classes drags org-wide coverage down and can fail an 85 percent coverage gate. Vendor the library test classes as well so the library covers itself during RunLocalTests.

Why does commitWork fail with REQUIRED_FIELD_MISSING in fflib?

The Unit of Work commits SObjectTypes in the order listed in Application.UnitOfWork, so a child listed before its parent fails on the lookup field at insert time. Reorder the list so parents such as Account appear before children such as Opportunity and OpportunityLineItem.