The FieloPLT.SObjectService class includes three methods.
Process Records (processRecords)
static void FieloPLT.SObjectService.processRecords (List<SObject> records, Map<Id, SObject> existingRecords)
Enables the Rules Engine to process records when they are both created and updated. Only records of objects which have undergone Rule Trigger configuration are processed.
Parameters
| Parameter | Type | Description |
|---|---|---|
| records | List<SObject> | A list of records to process. |
| existingRecords | Map<Id,SObject> | Previous records before their update. You should enter NULL when inserting records. |
Records should be inserted in the database.
Return Value
| Type | Description |
|---|---|
| Void | Void. |
trigger Event on FieloPLT__Event__c (after insert, after update) {
SObjectService.processRecords((List<FieloPLT__Event__c>) Trigger.new, Trigger.oldmap);
}Revert Records (revertRecords)
static Map<Id,String> FieloPLT.SObjectService.revertRecords (Set<Id> recordIds)
Lets you reverts a set of object IDs from records which are already processed. Processed records and all Transactions related to them are completely reverted.
You can only revert Transactions that gave Points but not the ones giving Instant Rewards and Badges.
Parameters
| Parameter | Type | Description |
|---|---|---|
| recordIds | Set<Id> | IDs of objects to be reverted. |
Return Value
| Type | Description |
|---|---|
Map<Id,String> | Map of errors from records IDs. If operation is successful, value is an empty map. |
Set IDsSet of IDs must be from the same object.
Set<Id> eventIds = new Set<Id>();
for(FieloPLT__Event__c event : [SELECT Id FROM FieloPLT__Event__c LIMIT 10]){
eventIds.add(event.Id);
}
Map<Id,String> resultsMap = FieloPLT.SObjectService.revertRecords(eventIds);
if(!resultsMap.isEmpty()){
for(Id recordId : resultsMap.keySet()){
ApexPages.addMessage(new ApexPages.Message(severity.ERROR, resultsMap.get(recordId)));
}
}Simulate Record Processing (processRecordsSimulator)
static Map <String, List<Sobject>> FieloPLT.SObjectService.processRecordsSimulator (List<SObject> records, Map<Id,SObject> existingRecords, Set<Id> memberIds)
Simulates how the Rules Engine processes records. Records are processed when they are both created and updated, as long as they meet the condition set in the Rule Trigger created for the object.
Parameters
| Parameter | Type | Description |
|---|---|---|
| records | List<SObject> | Records to be processed. |
| existingRecords | Map<Id,SObject> | Previous records before their update. They must be Null when inserting records. |
| memberIds | Set<Id> | Set of Members IDs used to simulate record processing. |
Return Values
| Type | Description |
|---|---|
Map<String, List<Sobject>> | Map of the inserted object API name |
List<FieloPLT__Event__c> records = new List<FieloPLT__Event__c>();
records.add( new FieloPLT__Event__c(Name = 'test1', FieloPLT__Value__c = 100) );
Map<Id,SObject> existingRecords = new Map<Id,SObject>();
Set<Id> memberIds = new Set<Id>();
Map<String, List<Sobject>> FieloPLT.SobjectService.processRecordsSimulator(records, existingRecords, memberIds);