Virtual base repository that every Repository must extend from. This class provides base implementations for common repository CRUD operations. More specific implementations must be added to the extending classes. No SObject specific queries are to be added to this base class. SObject specific queries are to be added to the extending classes. All SObject specific queries are to be done WITH USER_MODE. All SObject specific queries are to contain a Limit Statement.
There are now overloads provided for all DML operations that allow unsafe DML operations to be performed but they require certain criteria be met as follows.
- Create an instance of this class using the overloaded constructor to permit unsafe DML operations.
- The calling code must provide an
Justification
ApexDoc annotation explaining why unsafe DML is required. 3. The code must be reviewed & approved.
TESTVISIBLE
SObject type of the repo.
private final sObjectTypeSchema.SObjectType
defaultFields set in the fetchById methods.
protected defaultSelectFieldsSet<String>
Boolean Sets the all Or none unless users explicitly set the allOrNone member to false, logic for the Create update upsert and delete methods.
public allOrNoneBoolean
Boolean Sets the allowUnsafe switch to true to allow, with required justifications, unsafe DML operations. Defaults to false
private final allowUnsafeBoolean
Constructor for virtual base repository. Sets the allOrNone boolean for DML to true by default and allowUnsafe to false by default, prohibiting DML statements executed in System Mode.
protected BaseRepo(Schema.SObjectType sObjectType)| Name | Type | Description |
|---|---|---|
| sObjectType | Schema.SObjectType | String determines the sObjectType that the Repository is associated with. |
Constructor for virtual base repository. Sets the allOrNone boolean for DML to true by default and allowUnsafe to input parameter.
protected BaseRepo(Schema.SObjectType sObjectType, Boolean allowUnsafe)| Name | Type | Description |
|---|---|---|
| sObjectType | Schema.SObjectType | String determines the sObjectType that the Repository is associated with. |
| allowUnsafe | Boolean | Boolean that dictates if unsafe DML operations are allowed for this Repo instance.,[object Object], By default, it is false so this overloading of ctor is only required when unsafe DML is required (so true) |
gets a record with the ID passed into the method.
public SObject fetchById(Id recordId)| Name | Type | Description |
|---|---|---|
| recordId | Id | Id of the record we want to fetch. |
SObject
SObject
gets a record with the ID passed into the method.
public SObject fetchById(Id recordId, Set<String> additionalFields)| Name | Type | Description |
|---|---|---|
| recordId | Id | Id of the record we want to fetch. |
| additionalFields | Set<String> | Set<String> Additional fields that get added the select statement. |
SObject
SObject
Safely queries the database enforces UserMode.
protected SObject fetch(String queryString, Map<String,Object> bindParams)| Name | Type | Description |
|---|---|---|
| queryString | String | query string passed to the database method. |
| bindParams | Map<String,Object> | Map<String, Object> key value map that binds the key to the value in the query. e.g 'recordId' => 'abcdefg' |
SObject
SObject[] Collection of SObject records.
Safely queries the database enforces UserMode.
protected SObject fetch(String queryString)| Name | Type | Description |
|---|---|---|
| queryString | String | query string passed to the database method. |
SObject
SObject[] Collection of SObject records.
Calculates the select clause by joining the strings in the defaultSelectFields List with commas.
protected String calculateSelectClause(Set<String> fields)| Name | Type | Description |
|---|---|---|
| fields | Set<String> | Set<String> fields to be added to the select clause. |
String
String Returns SELECT Field1, Field2.... statement
Utility for generating the FROM Clase
protected String calculateFromClause()String
String returns the FROM OBJECT clause.
Bulk insert method that can be overridden. Assures that all inserts are all or none and run in the context of the running user.
public virtual Database.SaveResult doCreate(List<SObject> records)| Name | Type | Description |
|---|---|---|
| records | List<SObject> | List<SObject> list of SObject records to be inserted. |
Database.SaveResult
Database.SaveResult[] Save results that contain info on the transaction.
Singular insert method that can be overridden. Assures that all inserts are all or none unless users explicitly set the allOrNone member to false, and run in the context of the running user.
public virtual Database.SaveResult doCreate(SObject record)| Name | Type | Description |
|---|---|---|
| record | SObject | SObject record to be inserted |
Database.SaveResult
Database.SaveResult Singular Save Result that contains info on the transaction.
Bulk update method that can be overridden. Assures that all updates are all or none unless users explicitly set the allOrNone member to false, and run in the context of the running user.
public virtual Database.SaveResult doUpdate(List<SObject> records)| Name | Type | Description |
|---|---|---|
| records | List<SObject> | List<SObject> records to be updated |
Database.SaveResult
Database.SaveResult[] Save results that contain info on the transaction.
singular method that can be overridden. Assures that all updates are all or none unless users explicitly set the allOrNone member to false, and run in the context of the running user.
public virtual Database.SaveResult doUpdate(SObject record)| Name | Type | Description |
|---|---|---|
| record | SObject | SObject record to be updated. |
Database.SaveResult
Database.SaveResult Singular Save Result that contains info on the transaction.
Bulk method that can be overridden. Assures that all upserts are all or none unless users explicitly set the allOrNone member to false, and run in the context of the running user.
public virtual Database.UpsertResult doUpsert(List<SObject> records)| Name | Type | Description |
|---|---|---|
| records | List<SObject> | List<SObject> records to be upserted. |
Database.UpsertResult
Database.UpsertResult[] Upsert results that contain info on the transaction.
Singular method that can be overridden. Assures that all upserts are all or none unless users explicitly set the allOrNone member to false, and run in the context of the running user.
public virtual Database.UpsertResult doUpsert(SObject record)| Name | Type | Description |
|---|---|---|
| record | SObject | SObject record to be upserted |
Database.UpsertResult
Database.UpsertResult Singular upsert result that contains info on the transaction.
Bulk method for record deletion that can be overridden. Assures all deletes are all or none unless users explicitly set the allOrNone member to false, and run in the context of the running user.
public virtual Database.DeleteResult doDelete(List<SObject> records)| Name | Type | Description |
|---|---|---|
| records | List<SObject> | List<SObject> records to be deleted |
Database.DeleteResult
Database.DeleteResult[] Delete results that contain info on the transaction.
Singular method for record deletion that can be overridden. Assures all deletes are all or none unless users explicitly set the allOrNone member to false, and run in the context of the running user.
public virtual Database.DeleteResult doDelete(SObject record)| Name | Type | Description |
|---|---|---|
| record | SObject | SObject record to be deleted |
Database.DeleteResult
Database.DeleteResult Singular Delete result that contains info on the transaction.
Overloads for all DML methods to execute in SYSTEM_MODE (unsafe mode). These methods should be used judiciously and require valid reason and approval to ensure there are no alternative options. Explicitly, they require the invoking code to be annotated in ApexDoc with custom annotation justification providing a description as to the need for unsafe DML operation.
protected SObject fetchByIdUnsafe(Id recordId)| Name | Type | Description |
|---|---|---|
| recordId | Id |
SObject
gets a record with the ID passed into the method, query executed in SYSTEM_MODE. NOTE: Checking that allow unsafe operations is enabled in overloaded method that we invoke. Calling code must provide an
Justification
ApexDoc annotation.
protected SObject fetchByIdUnsafe(Id recordId, Set<String> additionalFields)| Name | Type | Description |
|---|---|---|
| recordId | Id | Id of the record we want to fetch. |
| additionalFields | Set<String> | Set<String> Additional fields that get added the select statement. |
SObject
SObject containing the requested additionalFields and default fields for our SObject.
UnsafeDmlAttemptedException: if this repository was NOT instantiated with unsafe operations enabled
Queries the database explicitly overriding User Mode
protected SObject fetchUnsafe(String queryString, Map<String,Object> bindParams)| Name | Type | Description |
|---|---|---|
| queryString | String | query string passed to the database method. |
| bindParams | Map<String,Object> | Map<String, Object> key value map that binds the key to the value in the query. e.g 'recordId' => 'abcdefg' |
SObject
SObject[] Collection of SObject records.
UnsafeDmlAttemptedException: if this repository was NOT instantiated with unsafe operations enabled
Queries the database explicitly overriding User Mode. NOTE: Checking that allow unsafe operations is enabled in overloaded method that we invoke. Calling code must provide an
Justification
ApexDoc annotation.
protected SObject fetchUnsafe(String queryString)| Name | Type | Description |
|---|---|---|
| queryString | String | query string passed to the database method. |
SObject
SObject[] Collection of SObject records.
UnsafeDmlAttemptedException: if this repository was NOT instantiated with unsafe operations enabled
Bulk insert method that can be overridden. Assures that all inserts are all or none and runs in system context, overriding the standard USER_MODE requirement. WARNING: Calling code must provide an
Justification
ApexDoc annotation.
protected Database.SaveResult doCreateUnsafe(List<SObject> records)| Name | Type | Description |
|---|---|---|
| records | List<SObject> | List<SObject> list of SObject records to be inserted. |
Database.SaveResult
Database.SaveResult[] Save results that contain info on the transaction.
UnsafeDmlAttemptedException: if this repository was NOT instantiated with unsafe operations enabled
Bulk insert method that can be overridden. Insert is executed in the system context NOTE: Checking that allow unsafe operations is enabled in overloaded method that we invoke. WARNING: Calling code must provide an
Justification
ApexDoc annotation.
protected Database.SaveResult doCreateUnsafe(SObject record)| Name | Type | Description |
|---|---|---|
| record | SObject | SObject record to be inserted. |
Database.SaveResult
Database.SaveResult Save results that contain info on the transaction.
UnsafeDmlAttemptedException: if this repository was NOT instantiated with unsafe operations enabled
Bulk update method that can be overridden. Assures that all updates are all or none unless users explicitly set the allOrNone member to false, and run in system context WARNING: Calling code must provide an
Justification
ApexDoc annotation.
protected Database.SaveResult doUpdateUnsafe(List<SObject> records)| Name | Type | Description |
|---|---|---|
| records | List<SObject> | List<SObject> records to be updated |
Database.SaveResult
Database.SaveResult[] Save results that contains info on the transactions.
UnsafeDmlAttemptedException: if this repository was NOT instantiated with unsafe operations enabled
Bulk insert method that can be overridden. Update is executed in the system context NOTE: Checking that allow unsafe operations is enabled in overloaded method that we invoke. WARNING: Calling code must provide an
Justification
ApexDoc annotation.
protected Database.SaveResult doUpdateUnsafe(SObject record)| Name | Type | Description |
|---|---|---|
| record | SObject | SObject record to be updated. |
Database.SaveResult
Database.SaveResult Save results that contain info on the transaction.
UnsafeDmlAttemptedException: if this repository was NOT instantiated with unsafe operations enabled
Bulk method that can be overridden. Assures that all upserts are all or none unless users explicitly set the allOrNone member to false, and run in system context. WARNING: Calling code must provide an
Justification
ApexDoc annotation.
protected Database.UpsertResult doUpsertUnsafe(List<SObject> records)| Name | Type | Description |
|---|---|---|
| records | List<SObject> | List<SObject> records to be upserted. |
Database.UpsertResult
Database.UpsertResult[] Upsert results that contains info on the transaction.
UnsafeDmlAttemptedException: if this repository was NOT instantiated with unsafe operations enabled
Singular method that can be overridden. Assures that all upserts are all or none unless users explicitly set the allOrNone member to false, and run in the system context NOTE: Checking that allow unsafe operations is enabled in overloaded method that we invoke. WARNING: Calling code must provide an
Justification
ApexDoc annotation.
protected Database.UpsertResult doUpsertUnsafe(SObject record)| Name | Type | Description |
|---|---|---|
| record | SObject | SObject record to be upserted |
Database.UpsertResult
Database.UpsertResult Singular upsert result that contains info on the transaction.
UnsafeDmlAttemptedException: if this repository was NOT instantiated with unsafe operations enabled
Bulk method for record deletion that can be overridden. Assures all deletes are all or none unless users explicitly set the allOrNone member to false, and run in system context.
WARNING: Calling code must provide an
Justification
ApexDoc annotation.
protected Database.DeleteResult doDeleteUnsafe(List<SObject> records)| Name | Type | Description |
|---|---|---|
| records | List<SObject> | List<SObject> records to be deleted |
Database.DeleteResult
Database.DeleteResult[] Delete results that contains info on the transaction.
UnsafeDmlAttemptedException: if this repository was NOT instantiated with unsafe operations enabled
Singular method for record deletion that can be overridden. Assures all deletes are all or none unless users explicitly set the allOrNone member to false, and run in the system context NOTE: Checking that allow unsafe operations is enabled in overloaded method that we invoke. WARNING: Calling code must provide an
Justification
ApexDoc annotation.
protected Database.DeleteResult doDeleteUnsafe(SObject record)| Name | Type | Description |
|---|---|---|
| record | SObject | SObject record to be deleted |
Database.DeleteResult
Database.DeleteResult Singular Delete result that contains info on the transaction.
UnsafeDmlAttemptedException: if this repository was NOT instantiated with unsafe operations enabled
Exception to be thrown when an attempt to execute Unsafe DML is made without configuring Repo correctly & providing required documentation/config.