Coder Social home page Coder Social logo

coding-with-the-force / salesforce-separation-of-concerns-and-the-apex-common-library Goto Github PK

View Code? Open in Web Editor NEW
88.0 88.0 19.0 173 KB

This repo hopes to better explain Separation of Concerns for Salesforce and how to leverage the Apex Common library to employ it in your org.

Apex 99.64% HTML 0.11% JavaScript 0.23% CSS 0.01%
apex apex-common apex-commons apex-mock apex-mocks salesforce salesforce-developers separation-of-concerns

salesforce-separation-of-concerns-and-the-apex-common-library's People

Contributors

coding-with-the-force avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

salesforce-separation-of-concerns-and-the-apex-common-library's Issues

Sample code to query related records //Suggested Wiki Update

If we need our query to include related record data we create an instance of our parent selector. In this case, Accounts and provide the query factory with the relationship.

 public List<Contact> selectWithAccountData(){
        fflib_QueryFactory contactQueryFactory = newQueryFactory();
        new AccountSelector().configureQueryFactoryFields(contactQueryFactory,
                Contact.AccountId.getDescribe().getRelationshipName());

        return Database.query(contactQueryFactory.toSOQL());
    }

Running this query will generate the following query string:
SELECT Account.AccountNumber, Account.Id,
Account.Industry, Account.Name, Account.NumberOfEmployees,
Account.Rating, AccountId,
Email, Id, Name, Phone, Title
FROM Contact
ORDER BY
Name ASC
NULLS FIRST

Update Wiki for the new Apex Database Access modes.

As of Dec 22nd the fflib_Selector was updated to use the Apex Data Access modes in its constructor.

Below is an example of a selector class that is set to run in usermode by default via the constructor. We must also provide a value for the use of field sets.

public inherited sharing class AccountSelector extends fflib_SObjectSelector {
 
    public AccountSelector(){
        super(false, DataAccess.USER_MODE);
    }
 
 
    public SObjectType getSObjectType() {
        //All selectors must implement
        return Account.SObjectType;
    }
 
    public List<SObjectField> getSObjectFieldList() {
        //All selectors must implement
        return new List<SObjectField>{
                Account.Id,
                Account.Name,
                Account.AccountNumber,
                Account.Industry,
                Account.Rating,
                Account.NumberOfEmployees
        };
 
    }   
}

If we want the selector to run in System mode, we configure that at the instance level.

AccountSelector accountSelector = new AccountSelector();
accountSelector.setDataAccess(fflib_SObjectSelector.DataAccess.SYSTEM_MODE);

An example query string would look like the following.
SELECT id, name, accountnumber,
industry, rating, numberofemployees, type, description
FROM Account
WITH SYSTEM_MODE
ORDER BY Name
ASC
NULLS FIRST
LIMIT 10

DML in Service/Domain Layer

You said in one video that we should put dmls in the service layer.
Does this mean, that if we have a trigger that executes on afterInsert and creates a new record (different object), this logic should go into a service layer?

files missing

Hi ,
The code for the 1st video SOC introduction is missing i guess, I could not find it can u please help me the code

Abstract domain classes

How do we handle for example record-type specific logic in the domain layer?
Imagine I have an object that calculates a currency field oninsert, but this logic differs for the record-type.

Would I make the domain class virtual? Or would I put the record-type specific logic into the service class for that object?

Test class

It would be really helpful to also see sample test classes!

Composite Services and IOC

Most of the examples i've seen of the Service layer using enterprise design patterns are where the service layer is orchestrating one or more domain or selector objects. I haven't seen any examples of an enterprise layer orchestrating services.
I know an instance of a Service could easily be constructed which self populates its dependencies...but that violates IOC (inversion of control) principles. Seems like you would need some entity responsible for providing DI (dependency injection) which manages the dependency mappings. Because as it stands, the Application class doesn't appear to support this concept.

For example, suppose the Task_ServiceImpl.class depended on one or more other services...then the approach below would not support proper IOC.

public static final fflib_Application.ServiceFactory service = new fflib_Application.ServiceFactory(new Map<Type, Type>{
Task_Service_Interface.class => Task_Service_Impl.class
})

Are there plans for supporting this concept?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.