Skip to content

Commit

Permalink
Issue #1 fixed - problem when executing WAV_OrgLimitSnapshot_SCH
Browse files Browse the repository at this point in the history
  • Loading branch information
P-E Gros committed Nov 8, 2022
1 parent a8d4710 commit 5032ac0
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions force-app/main/default/classes/WAV_OrgLimitSnapshot_SCH.cls
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,47 @@ public class WAV_OrgLimitSnapshot_SCH implements Schedulable {
***/
public static void execute(SchedulableContext context) {
System.debug('WAV_OrgLimitSnapshot_SCH.execute: START');

String limitsHeader = '"MeasureDate","Name","Value","Limit"\n';
String limitsData = '';
//String measureDate = '' + System.today();
String measureDate = '' + System.now();

List<WAV_Snapshot_CFG__mdt> limitList = [ select MasterLabel from WAV_Snapshot_CFG__mdt
where DataSet__c = 'WAV_OrgLimits'
and isActive__c = true];
List<WAV_Snapshot_CFG__mdt> limitList = [ SELECT MasterLabel FROM WAV_Snapshot_CFG__mdt
WHERE DataSet__c = 'WAV_OrgLimits'
AND isActive__c = true];
System.debug('WAV_OrgLimitSnapshot_SCH.execute: limit List fetched with size ' + limitList.size());

if ((limitList == null) || (limitList.size() == 0)) {
System.debug('WAV_OrgLimitSnapshot_SCH.execute: END / no limit to evaluate');
return;
}

Map<String,System.OrgLimit> limitMap = OrgLimits.getMap();
System.debug('WAV_OrgLimitSnapshot_SCH.execute: Map fetched with size ' + limitMap.size());

for (WAV_Snapshot_CFG__mdt limitIter : limitList) {
//system.debug('WAV_OrgLimitSnapshot_SCH.execute: processing limitKey ' + limitKey);
System.OrgLimit iterLimit = limitMap.get(limitIter.MasterLabel);
//system.debug('WAV_OrgLimitSnapshot_SCH.execute: iterLimit fetched ' + iterLimit);
limitsData += '"' + measureDate + '","' + limitIter.MasterLabel
+ '","' + iterLimit.getValue() + '","' + iterLimit.getLimit() + '"\n';
//system.debug('WAV_OrgLimitSnapshot_SCH.execute: processing limitKey ' + limitKey);
System.OrgLimit iterLimit = limitMap.get(limitIter.MasterLabel);
if (iterLimit != null) {
//system.debug('WAV_OrgLimitSnapshot_SCH.execute: iterLimit fetched ' + iterLimit);
limitsData += '"' + measureDate + '","' + limitIter.MasterLabel
+ '","' + iterLimit.getValue() + '","' + iterLimit.getLimit() + '"\n';
}
else {
System.debug(LoggingLevel.WARN,'WAV_OrgLimitSnapshot_SCH.execute: limit not found ' + limitIter.MasterLabel);
}
}
System.debug('WAV_OrgLimitSnapshot_SCH.execute: limitsHeader ready ' + limitsHeader);
System.debug('WAV_OrgLimitSnapshot_SCH.execute: limitsData ready ' + limitsData);

InsightsExternalData limitLoader = WAV_DataLoad_UTL.initLoader('WAV_OrgLimits');
System.debug('WAV_OrgLimitSnapshot_SCH.execute: loader ready');
WAV_DataLoad_UTL.addDataPart(limitLoader,limitsHeader + limitsData,1);
System.debug('WAV_OrgLimitSnapshot_SCH.execute: datapart added');
limitLoader.Action = 'Process';
if (!Test.isRunningTest()) update limitLoader;

System.debug('WAV_OrgLimitSnapshot_SCH.execute: END loading launched');
}
}

0 comments on commit 5032ac0

Please sign in to comment.