1

I read an article about the service layer here. The names for the services are OpportunitiesService.cls or AccountsService.cls. Does the names of the services always follow the pattern {plural Sobject}{Service}.cls? What are the best practices? I would like to create services with the following naming OpportunitiesCreator.cls or AccountsCreator.cls? is this a good practice?

1

To quote Andrew Fawcett, page 163 Salesforce Lightning Platform Enterprise Architecture

The actual name of the service can be pretty much anything you like, typically a major module or a significant object in your application. Make sure it is something from your application's vocabulary. If you've structured your application design well, your service class names should roughly fall into the groupings of your application's modules...

In our org, we have AccountsService, OrdersService, etc corresponding to major objects (Account, Order, ...) We also have services that don't directly correspond to a single SObject such as a SObjectFieldHistoriesService that deals with operations on field history records.

Be careful not to create services that are really methods. in your example, you might want something like an ActorsService with methods such as create(SObjectType sobjType) but I'm just speculating without more understanding of your use case.

Reference that fflib was based on: Patterns of Enterprise Application Architecture by the inestimable Martin Fowler

1
  • Thanks, @cropredy, without you my code writing would be a pain. Jan 27 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.