With the latest fflib, the trigger handler and domain logic were separated. I can see from the changes to the repo that previously, the Opportunities.cls domain class' onAfterInsert() method updates the account's fields by instantiating a UoW and an Accounts.cls domain class and calling its appropriate method and passing the UoW to finally commit the change.

Now with the separation, the logic in updateOpportunityActivityOnAccount, which is called with onAfterInsert(), calls the updateOpportunityActivity method on AccountsService.cls.

Question 1

Is it correct to say the TriggerHandler classes can call service methods if cross object updating is required?

Question 2

As I understand it, public domain methods take unitOfWork as a parameter. This becomes confusing if the TriggerHandler class is going to call a domain's method in a before context where unitOfWork is not needed. For example, consider the following scenario where the TriggerHandler class calls a method on the context record's domain class, but has to instantiate an unnecessary unitOfWork due to calling context being from onBeforeInsert.


    public override void onBeforeInsert()
        fflib_ISObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(new Schema.SObjectType[] { Interaction__c.SObjectType }); 

        // Assign ownership
        IInteractions interactions = Interactions.newInstance(this.records);


    public void assignOwnership(fflib_ISObjectUnitOfWork uow)
        // Collect channels
        Map<Id, Channel__c> channelsById = 
            new Map<Id, Channel__c>( (List<Channel__c>) Application.Selector.selectById( getChannelIds() ) );

        for (Interaction__c interaction : (List<Interaction__c>) getRecords())
            // Get channel
            Channel__c channel = channelsById.get(interaction.Interaction_Channel__c);

            // Assign ownership
            interaction.OwnerId = channel.OwnerId;


Of course, the unitOfWork parameter on the domain class is useful for when the method is called from a service such as InteractionsServiceImpl, but is not always necessary as seen above. What is the correct way of handling that?

  • 2
    These questions are better posed on the apex-commons GitHub issues page where the fflib thoughtLeaders hang out
    – cropredy
    Commented Mar 1, 2023 at 18:44
  • Thanks! I have done so. Will close this question if it's answered there. Commented Mar 1, 2023 at 21:09


You must log in to answer this question.

Browse other questions tagged .