🚧 🚧 🚧
This project is only for pedagogical purposes. It is not intended to be used in production environments.
This was created to practice TDD and Design Patterns in Apex with the Radical One and Fonteva team members
🚧 🚧 🚧
abstract
Represents a Database that supports storing data both in-memory as well as in the Salesforce
database.
QDB db = QDB.getInstance();
db.doInsert(new Account(Name = 'Test Account'));
Returns an instance of the QDB class.
By default the Salesforce database is used, but if the code is running in a test context
then an in-memory database is used.
public static QDB getInstance()
An instance of the QDB class.
Inserts a single record into the database.
public abstract void doInsert(SObject recordToInsert)
Name | Type | Description |
---|---|---|
recordToInsert | SObject | The record to insert into the database. |
void
QDB db = QDB.getInstance();
db.doInsert(new Account(Name = 'Test Account'));
Inserts multiple records into the database.
public abstract void doInsert(List<SObject> recordsToInsert)
Name | Type | Description |
---|---|---|
recordsToInsert | List<SObject> | The records to insert into the database. |
void
QDB db = QDB.getInstance();
db.doInsert(new List<Account>{new Account(Name = 'Test Account 1'), new Account(Name = 'Test Account 2')});
Queries for records in the database.
public abstract List<SObject> query(QueryBuilder queryBuilder)
Name | Type | Description |
---|---|---|
queryBuilder | QueryBuilder | A QueryBuilder object that represents the query to run. |
List<SObject>
A list of records that match the query.
QDB db = QDB.getInstance();
List<SObject> accounts = db.query(QueryBuilder.of('Account').selectField('Name'));
// Returns a list of Account records with only the Name field populated.
Forces the QDB class to use the Salesforce database, regardless of the context.
public static void useSystemDB()
void
A class for building SOQL queries in Apex.
QueryBuilder query = QueryBuilder.of('Account')
.selectFields(new Set<String>{ 'Name', 'Id' })
.subselect(
QueryBuilder.of('Contacts')
.selectFields(new Set<String>{ 'Name', 'Id' })
.withLimitAmount(10)
)
Implements Iterable<QueryPart>
Creates a new QueryBuilder object with the specified object type.
public static QueryBuilder of(String objectType)
Name | Type | Description |
---|---|---|
objectType | String | The object type to query. |
When querying a child object, use the relationship name. |
A new QueryBuilder object.
Adds a set of fields to the SELECT clause of the query.
public QueryBuilder selectFields(Set<String> fields)
Name | Type | Description |
---|---|---|
fields | Set<String> | A set of field names to add to the SELECT clause. |
The QueryBuilder object.
Adds a field to the SELECT clause of the query.
public QueryBuilder selectField(String fieldName)
Name | Type | Description |
---|---|---|
fieldName | String | The field name to add to the SELECT clause. |
The QueryBuilder object.
Adds a subquery to the query.
public QueryBuilder subselect(QueryBuilder subquery)
Name | Type | Description |
---|---|---|
subquery | QueryBuilder | The subquery to add to the query. |
The QueryBuilder object.
Sets the maximum number of records to return.
public QueryBuilder withLimitAmount(Integer limitAmount)
Name | Type | Description |
---|---|---|
limitAmount | Integer | The maximum number of records to return. |
The QueryBuilder object.
Sets the offset amount for the query.
public QueryBuilder withOffsetAmount(Integer offsetAmount)
Name | Type | Description |
---|---|---|
offsetAmount | Integer | The offset amount for the query. |
The QueryBuilder object.