All the backend logic of ScoreHub is done using Apex Classes. No-code tools are not used for development. This section is meant to explain some key concepts that are utilized across the ScoreHub code.
ScoreHub relies on BaseSelector class to retrieve data for different sObjects. Concrete realizations of the BaseSelector class are used to retrieve data for a specific sObject
To create a concrete realization of a BaseSelector class, the child class has to realize 3 methods:
public String sObjectApiName(): this method should return the API name of the sObjectpublic override Set<String> fieldApiNames(): returns a list of field API names that will be retrieved by the Selector class
BaseSelector class provides a set of methods that can be used to retrieve data without the need to create additional methods on the concrete selector class:
public List<sObject> getByFieldValue(String filterFieldApiName, String compOperator, Object values)
Parameters:
filterFieldApiName: API name of the field that is going to be used for filtering SOQL requestcompOperator: Comparison operator for data filteringvalues: a value (set of values) that will be used for filtering data
Example:
getByFieldValue('Name', 'IN', new Set<String>{'Name 1', 'Name 2', 'Name 3'})
equals to this SOQL
Set<String> names = new Set<String>{'Name 1', 'Name 2', 'Name 3'}
[...WHERE Name IN :names]
public List<sObject> getByIds(Set<Id> ids)
Parameters:
ids: API name of the field that is going to be used for filtering SOQL request
Example:
getByIds(new Set<Id>{'Id1', 'Id2', 'Id3'})
equals to this SOQL
Set<Id> ids = new Set<Id>{'Id1', 'Id2', 'Id3'}
[...WHERE Id IN :ids]
public List<sObject> getAll()
Example:
getAll()
equals to this SOQL
[SELECT ... FROM ... ]
This method should be used with caution since it doesn't have any limitations and can result in SOQL query limit
Logger class is used to save information about issues that might have occurred in a system. This class will be refined in the future to allow for storing more granular information about the issues.
There are two main methods of a Logger class that are used for storing runtime issues:
public static void saveSingleLog(String log)
Stores a single issue in a Log__c sObject. Asynchronous and can be called from cached LWC methods.
Example:
} catch (Exception e) {
Logger.saveSingleLog('Error message');
}
public void addLog(String log)
Adds a new log record, but doesn't commit changes. commitChanges() has to be called once all issues are collected
ControllerResponse class is used to wrap the result of the execution of the backend controller and have more control over the issues (expected and unexpected) that might occur during the backend controller execution.
There are 3 methods that can be used to return the result of a backend controller execution in the form of Map<String, Object>:
public static Map<String, Object> success(Object obj)
Example:
@AuraEnabled(cacheable=true)
public static Map<String, Object> method(){
...
return ControllerResponse.success('value to pass to LWC');
}
public static Map<String, Object> error(String msg)
Example:
@AuraEnabled(cacheable=true)
public static Map<String, Object> method(){
Map<String, Object> result = new Map<String, Object>();
try {
...
return ControllerResponse.success('value to pass to LWC');
} catch (Exception e) {
...
result = ControllerResponse.error('error message displayed to user');
}
return result;
}
public static Map<String, Object> warning(Object msg)
Example:
@AuraEnabled(cacheable=true)
public static Map<String, Object> method(){
Map<String, Object> result = new Map<String, Object>();
try {
if (all good) {
return ControllerResponse.success('value to pass to LWC');
} else {
return ControllerResponse.success('Handled issue');
}
} catch (Exception e) {
...
result = ControllerResponse.error('error message displayed to user');
}
return result;
}