0

Everyone! I have a question - what if i don't want what kind of objects i will get? One day it is Accounts, next day - Opportunities, etc. Can I write Application.cls something like this?

{
    // Configure and create the UnitOfWorkFactory for this Application
    public static final fflib_Application.UnitOfWorkFactory UnitOfWork = 
        new fflib_Application.UnitOfWorkFactory(
                new List<SObjectType> {
                    SObject.SObjectType }); 

    // Configure and create the ServiceFactory for this Application
    public static final fflib_Application.ServiceFactory Service = 
        new fflib_Application.ServiceFactory( 
            new Map<Type, Type> {
                    ISObjectService.class => SObjectsServiceImpl.class});

    // Configure and create the SelectorFactory for this Application
    public static final fflib_Application.SelectorFactory Selector = 
        new fflib_Application.SelectorFactory(
            new Map<SObjectType, Type> {
                    SObject.SObjectType => SObjectsSelector.class });

    // Configure and create the DomainFactory for this Application
    public static final fflib_Application.DomainFactory Domain = 
        new fflib_Application.DomainFactory(
            Application.Selector,
            new Map<SObjectType, Type> {
                    SObject.SObjectType => SObjects.Constructor.class });
}

So all other layers will be only for SObject, as I can understand. Is it real life decision or not? Thanks)

1 Answer 1

1

No, you really can't write it this way. The purpose of these classes is to be replicated for each separate Application, which will have specific implementation behaviors. The fflib framework works dynamically, but it needs concrete data types at the application level.

3
  • So I have 150 custom objects in application - I must write code for every custom object, right? How can I decrease number of code?
    – oldgunner
    Commented Jul 2, 2021 at 15:45
  • @oldgunner There are ways to write it dynamically, such as getting a describe list and dynamically generating them, but typically applications are typically smaller with only a few objects. It's a rare use case to need every object.
    – sfdcfox
    Commented Jul 2, 2021 at 15:50
  • Thanks a lot for your answer! I will try to decompose my application
    – oldgunner
    Commented Jul 2, 2021 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .