|
11 | 11 | public without sharing class LogHandler extends LoggerSObjectHandler { |
12 | 12 | private static final Map<String, LogStatus__mdt> MOCK_LOG_STATUS_TO_STATUS = new Map<String, LogStatus__mdt>(); |
13 | 13 |
|
14 | | - private static final List<OrganizationLimit> ORGANIZATION_LIMITS { |
| 14 | + private static final List<SerializableOrganizationLimit> ORGANIZATION_LIMITS { |
15 | 15 | get { |
16 | 16 | if (ORGANIZATION_LIMITS == null) { |
17 | 17 | ORGANIZATION_LIMITS = loadOrganizationLimits(); |
@@ -40,7 +40,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { |
40 | 40 | this.loggerScenariosById = queryLoggerScenarios(this.logs); |
41 | 41 |
|
42 | 42 | this.setClosedStatusFields(); |
43 | | - this.setOrganizationLimits(); |
| 43 | + this.setSerializableOrganizationLimits(); |
44 | 44 | // The log OwnerId field should support being manually changed, so only auto-set it on insert |
45 | 45 | this.setOwnerId(); |
46 | 46 | this.setParentLog(); |
@@ -87,7 +87,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { |
87 | 87 | } |
88 | 88 | } |
89 | 89 |
|
90 | | - private void setOrganizationLimits() { |
| 90 | + private void setSerializableOrganizationLimits() { |
91 | 91 | if (LoggerParameter.STORE_ORGANIZATION_LIMITS == false) { |
92 | 92 | return; |
93 | 93 | } |
@@ -285,21 +285,22 @@ public without sharing class LogHandler extends LoggerSObjectHandler { |
285 | 285 | return logStatusNameToStatus; |
286 | 286 | } |
287 | 287 |
|
288 | | - private static List<OrganizationLimit> loadOrganizationLimits() { |
289 | | - List<OrganizationLimit> organizationLimits = new List<OrganizationLimit>(); |
| 288 | + private static List<SerializableOrganizationLimit> loadOrganizationLimits() { |
| 289 | + List<SerializableOrganizationLimit> serializableOrganizationLimits = new List<SerializableOrganizationLimit>(); |
| 290 | + Map<String, System.OrgLimit> systemOrgLimits = System.OrgLimits.getMap(); |
290 | 291 |
|
291 | | - List<String> systemOrgLimitNames = new List<String>(System.OrgLimits.getMap().keySet()); |
| 292 | + List<String> systemOrgLimitNames = new List<String>(systemOrgLimits.keySet()); |
292 | 293 | systemOrgLimitNames.sort(); |
293 | 294 | for (String systemOrgLimitName : systemOrgLimitNames) { |
294 | | - System.OrgLimit systemOrgLimit = System.OrgLimits.getMap().get(systemOrgLimitName); |
295 | | - OrganizationLimit organizationLimit = new OrganizationLimit(); |
296 | | - organizationLimit.Name = systemOrgLimit.getName(); |
297 | | - organizationLimit.Used = systemOrgLimit.getValue(); |
298 | | - organizationLimit.Max = systemOrgLimit.getLimit(); |
299 | | - organizationLimits.add(organizationLimit); |
| 295 | + System.OrgLimit systemOrgLimit = systemOrgLimits.get(systemOrgLimitName); |
| 296 | + SerializableOrganizationLimit serializableOrganizationLimit = new SerializableOrganizationLimit(); |
| 297 | + serializableOrganizationLimit.Name = systemOrgLimit.getName(); |
| 298 | + serializableOrganizationLimit.Used = systemOrgLimit.getValue(); |
| 299 | + serializableOrganizationLimit.Max = systemOrgLimit.getLimit(); |
| 300 | + serializableOrganizationLimits.add(serializableOrganizationLimit); |
300 | 301 | } |
301 | 302 |
|
302 | | - return organizationLimits; |
| 303 | + return serializableOrganizationLimits; |
303 | 304 | } |
304 | 305 |
|
305 | 306 | private static Map<Id, LoggerScenario__c> queryLoggerScenarios(List<Log__c> logs) { |
@@ -344,9 +345,12 @@ public without sharing class LogHandler extends LoggerSObjectHandler { |
344 | 345 | MOCK_LOG_STATUS_TO_STATUS.put(logStatus.MasterLabel, logStatus); |
345 | 346 | } |
346 | 347 |
|
| 348 | + // The class System.OrgLimit isn't serializable, so this DTO is used instead |
| 349 | + // so that the serialized string can be stored in Log__c.OrganizationLimits__c. |
| 350 | + // The JSON data is then displayed on the Log__c page using a custom LWC. |
347 | 351 | @SuppressWarnings('PMD.ApexDoc') |
348 | 352 | @TestVisible |
349 | | - private class OrganizationLimit { |
| 353 | + private class SerializableOrganizationLimit { |
350 | 354 | public String Name { get; set; } |
351 | 355 | public Integer Used { get; set; } |
352 | 356 | public Integer Max { get; set; } |
|
0 commit comments