Configure Off Limits Recalculator API
In order to resolve the Salesforce limits raised during OL calculation, we have two global methods that receive a set of contact Ids, so the calculation can be done for a subset of contacts.
These two new global methods receive a json string as a parameter that internally are converted to a set of contact Ids and policy Id. This document will show how to format this json parameter.
Also, we will show an example of how to call these new methods using a sample batch.
New Global Methods
The OffLimitRecalculator class now has 2 new methods. The old ones are still available.
Method Versions | Recalculation Method | Properties |
---|---|---|
Old methods | global static void recalculatePoliciesForContacts | (Set<Id> contactIds) |
global static void recalculateATSOrJobRolePolicy |
(Id policyId) |
|
New methods
|
global static void recalculatePoliciesForContacts | (String jsonData) |
global static void recalculateATSOrJobRolePolicy |
(String jsonData) |
The new methods receive a json string.
global static void recalculatePoliciesForContacts(String jsonData)
-
This method only accepts a Set<Id> contactIds.
-
The map accepts as key a String and value as Object
-
The SOQL query is just an example to build this set and should be adjusted.
-
The map only accepts the key contactIds. See example below
Recalculate Off Limit Policies for a Given Set of Contact Records
-
@param jsonData the input params for the API
-
contactIds : set of Contact Ids
-
Example in How to Call:
Map<String, Object> params = new Map<String, Object>();
Map<Id, Contact> contactMap = new Map<Id, Contact>([SELECT Id FROM Contact WHERE Name Like 'A%' LIMIT 10]);
Set<Id> contactIds = new Set<Id>();
contactIds.addAll(contactMap.keySet());
params.put('contactIds', contactIds);
String jsonParam = JSON.serialize(params);
OffLimitRecalculator.recalculatePoliciesForContacts(jsonParam);
Global Static Void RecalculateATSOrJobRolePolicy (String jsonData)
- This method previously accepted only the policyId, but now also accepts accepts a Set<Id> contactIds
- The map accepts as key a String and value as Object
- The SOQL query is just an example to build this set and should be adjusted.
- The map only accepts the key 'policyId' that contains a single policyId but also a set of contact ids with the key 'contactIds'.
Recalculate a Single ATS Stage or Job Role Off Limit Policy for a Set of Contact Ids
@param jsonData the input params for the API
Id policyId : the Id of the policy
contactIds : a list of contact Ids
Example in How to Call:
Map<String, Object> params = new Map<String, Object>();params.put('policyId', 'a2X7z000000wD6XEAU');Map<Id, Contact> contactMap = new Map<Id, Contact>([SELECT Id FROM Contact WHERE Name Like 'A%' LIMIT 10]);
Set<Id> contactIds = new Set<Id>();
contactIds.addAll(contactMap.keySet());
params.put('contactIds', contactIds);
String jsonParam = JSON.serialize(params);
OffLimitRecalculator.recalculateATSOrJobRolePolicy(jsonParam);
Sample Batch to Call the OffLimitRecalculator. recalculateATSOrJobRolePolicy "API”
In order to call these new global methods, it's possible to use a batch (example below) that breaks down the contacts being passed to it.
The batch size may vary depending on how many ApplicationV2 records are matched by this OL ATS Policy, so the 200 batch can vary depending on the data.
// An ATS Policy
Id policyId = 'a2XRL000000Z0oL2AS';
// Sample query that selects some contacts using a externalId field
String contactsSoql = 'SELECT Id FROM Contact WHERE TR1__Data_External_Id__c >= \'00001\' AND TR1__Data_External_Id__c <= \'01500\'';
OFSampleBatch batch = new OFSampleBatch(policyId, contactsSoql);
Id batchJobId = Database.executeBatch(batch, 200);
Here is the code for the Batch class:
public with sharing class OFSampleBatch implements Database.Batchable<SObject> {
private Id policyId;
private String contactsSoql;
public OFSampleBatch(Id policyId, String contactsSoql) {
this.policyId = policyId;
this.contactsSoql = contactsSoql;
}
public Database.QueryLocator start(Database.BatchableContext context) {
return Database.getQueryLocator(contactsSoql, AccessLevel.SYSTEM_MODE);
}
public void execute(Database.BatchableContext context, List<Contact> scope) {
Map<String, Object> params = new Map<String, Object>();
params.put('policyId', policyId);
Map<Id, Contact> contactMap = new Map<Id, Contact>(scope);
Set<Id> contactIds = new Set<Id>();
contactIds.addAll(contactMap.keySet());
params.put('contactIds', contactIds);
String jsonParam = JSON.serialize(params);
TR1.OffLimitRecalculator.recalculateATSOrJobRolePolicy(jsonParam);
}
public void finish(Database.BatchableContext context) {
}
}