DataStore

DataStore - The DataStore class provides methods that execute basic queries automatically, eliminating the need for user-written queries. It stores data in a map format and supports selecting queries based on record IDs. Developers can utilize this class independently of the Step method.

 1   static void DataStoreMethod(){
 2        Account acc = new Account(
 3                Name = 'Breezz Test'
 4        );
 5        insert acc;
 6        forvendi.DataStore store = forvendi.BreezzApi.DATABASE.createDataStore();
 7        store.registerLoader(AccountTask);
 8        store.requestToLoad(acc.Id);
 9        store.loadData();
10        store.storeData('testObject', acc);
11        Account testAcc = (Account)store.getFromStore(acc.Id);
12   }

Use DataStore as follows:

1. Create an instance of DataStore

forvendi.DataStore store = forvendi.BreezzApi.DATABASE.createDataStore();

2. Register a custom data loader where user could write custom query:

store.registerLoader(AccountTask)

Where AccountTask is an Apex Class extending forvendi.DataStore.Loader

3. Request to load a record:

store.requestToLoad(acc.Id)

Requests acc record to be queried.

4. Load data:

store.loadData()

Loads requested data.

5. Store data:

store.storeData('testObject', acc)

Adds data to a store under ’testObject’ storeKey.

6. Get data from store:

store.getFromStore(acc.Id)

DataStore()

Default constructor.


registerLoader(Loader loader)

Registers custom data Loader

Parameters:

  • loader - the loader object to be added to the loaders set.

Return:

Self-reference to chain method invocations.


requestFields(String storeKey, Set<String> fields)

Requests to load - fieldsinto the ‘storeKey’ store bucket.

Parameters:

  • storeKey- name of the store bucket.
  • fields - requested field names

requestToLoad()


requestToLoad(String storeKey, String key, Set<String> fields)

Requests to load an entry with ‘key’ identifier into the ‘storeKey’ store bucket.

Parameters:

  • storeKey - name of the store bucket.
  • key - record/entity/entry identifier
  • fields - requested field names

requestToLoad(String storeKey, String key)

Requests to load an entry with ‘key’ identifier into the ‘storeKey’ store bucket. Parameters:

  • storeKey - name of the store bucket.
  • key - record/entity/entry identifier

requestToLoad(String storeKey, Id key, Set<String> fields)

Requests to load SObject record with ‘key’ Id into the ‘storeKey’ store bucket.

Parameters:

  • storeKey - name of the store bucket.
  • key - salesforce record identifier
  • fields - requested salesforce object field names

requestToLoad(String storeKey, Id key, Set<SObjectField> fields)

Requests to load SObject record with ‘key’ Id into the ‘storeKey’ store bucket.

Parameters:

  • storeKey - name of the store bucket.
  • key - salesforce record identifier
  • fields - requested salesforce object field names

requestToLoad(String storeKey, Id key)

Requests to load SObject record with ‘key’ Id into the ‘storeKey’ store bucket.

Parameters:

  • storeKey - name of the store bucket.
  • key - salesforce record identifier

requestToLoad(Id key, Set<String> fields)

Requests to load SObject record with ‘key’ Id into the SObjectType store bucket (SObjectType is calculated base on the Id value)

Parameters:

  • key - salesforce id fields - requested salesforce object field names

requestToLoad(Id key, Set<SobjectField> fields)

Requests to load SObject record with ‘key’ Id into the SObjectType store bucket (SObjectType is calculated base on the Id value)

Parameters:

  • key - salesforce id
  • fields - requested salesforce object field names

requestToLoad(Id key)

Requests to load SObject record with ‘key’ Id into the SObjectType store bucket (SObjectType is calculated base on the Id value)

Parameters: key - salesforce id


requestToLoad(List<Id> ids, Set<String> fields)

Requests to load SObject record with ‘key’ Id into the SObjectType store bucket (SObjectType is calculated base on the Id value)

Parameters:

  • ids - salesforce ids
  • fields - requested salesforce object field names

requestToLoad(List<Id> ids)

Requests to load SObject record with ‘key’ Id into the SObjectType store bucket (SObjectType is calculated base on the Id value)


loadData()

Loads requested data using custom and dynamic SObject Loaders.


getKeys(String storeKey)

Returns all keys from the ‘storeKey; store bucket

Parameters:

  • storeKey - store name.

Return:

Set of unique keys.


getIds(SObjectType type)

Returns all ids from the key set for SObjectType store bucket.


getIds(String storeKey)

Returns all ids from the ‘storeKey’ store bucket.


getRequestedFields(String storeKey)

Returns all field names from the ‘storeKey’ bucket. Parameters:

  • storeKey - store name.

Return:

Set of unique field names keys.


getFromStore()


getFromStore(SObjectType type)

Returns data stored under the given SobjectType from the data store.

Parameters:

  • type - The SObjectType object to retrieve data for.

Return:

The data stored in the data store under the given SObjectType.


getFromStore(Id recordId)

Returns data stored under the given Id from the data store.

Parameters:

  • recordId - The SObjectType object to retrieve data for.

Return:

The data stored in the data store for the SObject represented by the given Id.


getFromStore(String storeKey)

Returns data stored under the given Id from the data store.

Parameters:

  • storeKey - The SObjectType object to retrieve data for.

Return:

The data stored in the data store for the SObject represented by the given storeKey.


storeData(String storeKey, Object data)

Add data under storeKey.

Parameters:

  • storeKey - The key to store the data under.
  • data - The data to store.

storeGlobalData(String storeKey, Object data)

Add data under global store key. Global store is shared in all DataStore instances till the end of transaction.

Parameters:

  • storeKey - The key to store the data under.
  • data - The data to store.

hasInStore(SObject type)

Checks if the store has data under the selected store key.

Parameters:

  • type - The type of data to check for.

Return:

A boolean indicating whether the store has data under the specified store key.


hasInStore(String storeKey)

Checks if the store has data under the selected store key.

Parameters:

  • storeKey - The key to check for data under.

Return:

A boolean indicating whether the store has data under the specified store key.


notInStore(SObjectType type)

Checks if the store has data under the selected store key.

Parameters:

  • type - The type of data to check for.

Return:

True if there is no data under the given type, false otherwise..


notInStore(String storeKey)

Checks if the store has data under the selected store key.

Parameters:

  • storeKey - The key to check for data under.

Return:

True if there is no data under the given type, false otherwise.


clear()

Clears the stored data and the identifiers and requested fields from the DataStore instance.