-
Notifications
You must be signed in to change notification settings - Fork 0
The MockSoql.StaticResults Class
Not all testing scenarios require the creation of a custom MockSoql.Simulator object. Most simple use cases can be handled by using the included MockSoql.StaticResults object.
This object cannot be directly constructed. Create an instance of this object by calling the 0-argument versions of the MockSoql.setGlobalMock() static method, or the setMock() instance method.
This object implements MockSoql.Simulator interface, and includes methods which allow callers to inject a static list of results, or an exception to be thrown. Whenever the query runs, the injected results are returned.
Injects an error to be thrown each time the query runs. Callers can provide a specific exception object, if desired. The 0-argument overload of this method will inject a generic System.QueryException.
MockSoql.StaticResults withError(System.Exception error)MockSoql.StaticResults withError()
DatabaseLayer.useMocks();
// Queries will always throw a System.QueryException:
MockSoql.setGlobalMock()?.withError();
// Queries will always throw some other exception type:
System.Exception someOtherError = new System.CalloutException();
MockSoql.setGlobalMock()?.withError(someOtherError);Injects a static list of results. This list will be returned each time the query runs.
MockSoql.StaticResults withResults(List<Object> results)
DatabaseLayer.useMocks();
Account mockAccount = (Account) new MockRecord(Account.SObjectType)?.withId()?.toSObject();
// Queries will always return the provided List<Object>
MockSoql.setGlobalMock()?.withResults(new List<Account>{ mockAccont });- 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