sf-fflib-domain-service-uow

Implements fflib Apex domain classes, service layers, and Unit of Work transaction patterns.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing triggers, validation logic, and multi-object transactions in an fflib-based Salesforce org requires knowing exactly where each piece of logic belongs; this Skill provides the dispatch tables, API signatures, and anti-patterns for the write side of Apex Enterprise Patterns. ## Core Features & Use Cases - Domain Layer Guidance: One-line trigger dispatch via fflib_SObjectDomain.triggerHandler, onApplyDefaults/onValidate overrides, Configuration flags, and Constructor inner class requirements. - Service Layer Patterns: Interface plus implementation plus static shim structure, bulk-first signatures, transaction ownership rules, and thin @AuraEnabled/@InvocableMethod entry points. - Unit of Work Mastery: registerNew/registerDirty/registerRelationship chains, platform event publishing after success or failure, custom IDML with USER_MODE access, and commit ordering. - Use Case: When an Opportunity closes won, build a service that creates a Project and child tasks in one transaction, publishes a platform event only on commit, and exposes the same logic to LWC and Flow. ## Quick Start Ask the assistant to write an fflib trigger, domain class, and service with a Unit of Work that creates Projects from closed-won Opportunities.

Frequently Asked Questions about sf-fflib-domain-service-uow

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

FAQPage Schema
How do I write a trigger in an fflib Salesforce org?▼

Write a one-line trigger body calling fflib_SObjectDomain.triggerHandler with your domain class. The domain class must extend fflib_SObjectDomain and expose a public Constructor inner class implementing IConstructable so the dispatcher can instantiate it.

Where should business logic go in Apex Enterprise Patterns?▼

Field defaults belong in domain onApplyDefaults, record validation in onValidate, and cross-object transactions in a service method that owns the Unit of Work. Domain classes never query or commit; selectors handle reads and services call commitWork exactly once.

How does fflib Unit of Work handle parent-child relationships?▼

Use registerNew with the child record, the lookup field token, and the parent record; the Unit of Work defers the lookup assignment until the parent is inserted. The Application.UnitOfWork type list must order parents before children for inserts to resolve correctly.

Can I call commitWork inside a domain class or trigger?▼

No, domain classes must accept the caller's fflib_ISObjectUnitOfWork as a parameter and only register work. The service method that created the Unit of Work owns the transaction and is the only place that calls commitWork.

How do I enforce user-mode DML with fflib Unit of Work?▼

Wire fflib_SObjectUnitOfWork.UserModeDML once in a custom UnitOfWorkFactory subclass inside Application.cls rather than at every call site. UserModeDML runs inserts, updates, deletes, and upserts with AccessLevel.USER_MODE, enforcing object and field permissions.

When should I not use the fflib domain and service pattern?▼

Skip it for orgs using hand-rolled trigger handler frameworks without fflib, and for pure read scenarios which belong to the selector layer. Simple single-field validation expressible in formula syntax is better handled by declarative validation rules.