-
Notifications
You must be signed in to change notification settings - Fork 0
Plugin: Soql.PreAndPostProcessor
Jason Siders edited this page Aug 19, 2025
·
4 revisions
This plugin allows developers to define logic to run immediately before, and/or immediately after a SOQL operation runs. This can be used for specialized functions, like logging.
First, create an apex class that will be used to define your logic. Requirements:
- Class must be
public. - Class must have a
public0-arg constructor (either explicit or implicit). - Class must implement the
Dml.PreAndPostProcessorinterface.
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();
}
}Next, create a Database Layer Setting/DatabaseLayerSetting__mdt custom metadata record, called "Default" (unless one already exists).
Finally, list your apex class from the previous step in the SOQL: Pre & Post Processor field, as shown below:
Once set up, the framework will do the following:
- Call your class's
processPreSoqlmethod immediately before processing a SOQL operation - Call your class's
processPostSoqlmethod immediately after processing a SOQL operation - Call your class's
processSoqlErrormethod if an exception is thrown during a SOQL operation. After the interface method runs, the exception will be re-thrown.
- Generating Test Records
- Dml
- Soql
- Cmdt
- Plugins
- DatabaseLayer
- Dml
- MockDml
- MockRecord
- Cmdt
- MockCmdt
- 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