HomeGuidesDeveloper HubRelease Notes
Get supportBook a chat
Developer Hub

FieloPLT.SObjectService Class

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 a Behavior Type with trigger deployed and at least one Action will be processed.

Parameters

ParameterTypeDescription
recordsList<SObject>A list of records to process.
existingRecordsMap<Id,SObject>Previous records before their update. You should enter NULL when inserting records.
❗️

Critical Considerations

The records to be processed must already exist in the database before calling this method.

No more than 200 records should be included per method call. Batches larger than 200 records may cause your org to exceed its governor limits.

Return Value

TypeDescription
VoidVoid.

Process Records (processRecords)

  • Check below an example of how the API can be used:
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

ParameterTypeDescription
recordIdsSet<Id>IDs of objects to be reverted.

Return Value

TypeDescription
Map<Id,String>Map of errors from records IDs. If operation is successful, value is an empty map.
❗️

Set IDs

Set of IDs must be from the same object.

Revert Records (revertRecords)

  • Check below an example of how the API can be used:
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

ParameterTypeDescription
recordsList<SObject>Records to be processed.
existingRecordsMap<Id,SObject>Previous records before their update. They must be Null when inserting records.
memberIdsSet<Id>Set of Members IDs used to simulate record processing. In this case, the IDs must be from the Members who will receive the reward.

Return Values

TypeDescription
Map<String, List<Sobject>>Map of the inserted object API name

Simulate Record Processing (processRecordsSimulator)

  • Check below an example of how the API can be used:
// Test processRecordsSimulator

//Id memberID = [ SELECT ID from FieloPLT__Member__c limit 1].Id;
Id memberID = 'replace by your memberId';
List<FieloPLT__Event__c> records = new List<FieloPLT__Event__c>();
records.add( new FieloPLT__Event__c(
    	FieloPLT__Member__c = memberID,
        FieloPLT__Value__c = 100,
    	FieloPLT__EventDate__c = date.newInstance(2020, 12, 10) )); // Add the FieloPLT__EventDate__c if needed to process the behaviour
Map<Id,SObject> existingRecords = new Map<Id,SObject>();
Set<Id> memberIds = new Set<Id>();
memberIds.add(memberID);
Map<String, List<Sobject>> res = FieloPLT.SobjectService.processRecordsSimulator(records, existingRecords, memberIds);
for(String cid : res.keyset()){
    System.debug(cid+ 'size=' + res.get(cid).size());
    for(SObject o : res.get(cid)){
    	System.debug(o);
    }
}