-
Notifications
You must be signed in to change notification settings - Fork 0
The Soql.PreAndPostProcessor Interface
This interface defines logic to be run before/after SOQL operations, as well as when an exception is thrown during a SOQL operation. You can use this for logging, or other specialized use cases.
All interface methods include a Soql.Request object. This object includes contextual information about the operation to be processed. See the Soql.Request class for the full list of parameters.
Read more about how this plugin works here.
Example:
public class SomeApexClass implements Soql.PreAndPostProcessor {
// This sample PreAndPostProcessor logs SOQL operations, using Nebula Logger:
public void processPreSoql(Soql.Request request) {
Logger.finest('About to query: ' + JSON.serialize(request));
Logger.finest(msg);
}
public void processPostSoql(Soql.Request request, List<Object> results) {
List<SObject> records = (List<Object> instanceof List<SObject>) ? results : new List<SObject>();
Logger.finest('Processed query ' + JSON.serialize(request))?.setRecord(records);
}
public void processDmlError(Soql.Request request, Exception error) {
String msg = request?.operation + ' error: ' + error;
Logger.error(msg)?.setExceptionDetails(error);
Logger.saveLog();
}
}Defines logic to run when an exception is thrown during a Soql operation.
Once this method runs, the framework will re-throw the Exception. If this is not desired, wrap your SOQL operation in a try/catch block. You cannot do this from within the interface itself.
void processSoqlError(Soql.Request request, Exception error)
Defines logic to be run immediately before a SOQL operation.
void processPreSoql(Soql.Request request)
Defines logic to be run immediately before a SOQL operation.
Note: This method is not called if the SOQL operation yields a thrown exception. You can use the processSoqlError method to handle these errors instead.
void processPostSoql(Soql.Request request, List<Object> databaseResults)
operation being processed:
| SOQL Operation | Database Result Type |
|---|---|
AGGREGATE_QUERY |
Soql.AggregateQuery |
COUNT_QUERY |
Integer |
GET_CURSOR |
Soql.Cursor |
GET_QUERY_LOCATOR |
Soql.QueryLocator |
QUERY |
List |
- Generating Test Records
- Dml
- Soql
- Cmdt
- Duplicates
- Plugins
- DatabaseLayer
- Dml
- MockDml
- MockRecord
- Cmdt
- MockCmdt
- Duplicates
- MockDuplicates
- MockSoql
-
Soql
- Soql.AggregateResult
- Soql.Aggregation
- Soql.Binder
- Soql.Builder
- Soql.Condition
- Soql.ConditionalLogic
- Soql.Criteria
- Soql.Cursor
- Soql.Function
- Soql.InnerQuery
- Soql.InvalidParameterValueException
- Soql.LogicType
- Soql.NullOrder
- Soql.Operation
- Soql.Operator
- Soql.ParentField
- Soql.PreAndPostProcessor
- Soql.QueryLocator
- Soql.Request
- Soql.Scope
- Soql.Selectable
- Soql.SortDirection
- Soql.SortOrder
- Soql.Subquery
- Soql.TypeOf
- Soql.Usage
- Soql.WhenClause