Apex Enterprise Patterns Flashcards

1
Q

Service Layer

A

Business logic - tasks, calculations and processes - for major modules/apps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Service Layer Design Considerations

A

Security - use ‘with sharing’ modifier, or if accessing records outside of User’s visibility - private Apex inner class ‘without sharing’.
SOC - keep validation, field values or calculations separate.
Marshalling - Leave error handling and messaging to the callers.
Make the service stateless.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Expose Services as API

A

Modify the class and method modifiers from ‘public’ to ‘global’.
If exposing to off-platform callers, use REST protocol.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Unit of Work in Service Code Methods

A

Initialize a single UOW and use it to scope all the work done by the service method.
Have the service layer logic register records w/the UOW when it executes.
Call the UOW commitWork method to bulkify and execute the DML.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Domain Layer

A

Object-specific default operations (triggers, validations, updates, etc. that should always execute on a database transaction).
Domain layer logic is specific to each individual object whereas services often are not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Domain Layer use

A

Used by Service Layer code relating to object - via Domain classes.
Used by Apex Triggers - CRUD (and undelete) of custom objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Domain Layer Design Considerations

A

Extension by containment - While you can’t extend an sObject, you can contain it with another class that complements the data with appropriate behavioral code (methods, properties, and so on).
OOP - use inheritance to abstract common behavioral code (methods, properties, etc.) into a shared base class.
Security - use ‘with sharing’ or ‘without sharing’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Selector Layer

A

Logic responsible for querying info from your custom objects and feeding it to your Domain and Service layer code.
UI Controllers and Batch Apex classes can also use them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Selector Layer Design Considerations

A

Methods - static or instance scope.
Mostly returning sObject lists.
When implementing Batch Apex use a selector method to return a QueryLocator.
Can use a custom Apex class to implement a wrapper for the query result to better reflect the queried info (instead of sObject).
Security - avoid using ’with sharing’ or ‘without sharing’. If a SOQL query need to access records outside of a user’s visibility - need to elevate the execution context briefly - use a private Apex inner class w/the ‘without sharing’ modifier.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Unit of Work

A

Helps simplify your code when performing multiple DML statements over related objects, avoids partial db updates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

IDoWork

A

An Apex Interface which is a UOW extension that describes work to be performed during the commitWork method (used for ops not covered with current uow methods ie: registerDIrty, etc. are not viable).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly