Last active
September 14, 2017 20:59
-
-
Save alan-morey/736a698873fb155018b5787db7c22338 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SetupAuditTrails { | |
public Map<String, Set<String>> getModifiedClassesSince(Id sinceTrailId) { | |
return getModifiedClassesSince(sinceDate(sinceTrailId)); | |
} | |
public Map<String, Set<String>> getModifiedClassesSince(DateTime sinceDate) { | |
Map<String, Set<String>> changes = new Map<String, Set<String>>(); | |
for (SetupAuditTrail t : [ | |
SELECT display | |
FROM SetupAuditTrail | |
WHERE createdDate >= :sinceDate | |
AND action IN ('changedApexClass', 'createdApexClass', 'deletedApexClass') | |
ORDER BY action, display | |
]) { | |
String[] parts = t.display.split(' '); | |
String action = parts[0]; | |
String className = parts[1]; | |
if (!changes.containsKey(action)) { | |
changes.put(action, new Set<String>()); | |
} | |
changes.get(action).add(className); | |
} | |
return changes; | |
} | |
public Map<String, Set<String>> getChangesSince(Id sinceTrailId) { | |
return getChangesSince(sinceDate(sinceTrailId)); | |
} | |
public Map<String, Set<String>> getChangesSince(DateTime sinceDate) { | |
Map<String, Set<String>> changes = new Map<String, Set<String>>(); | |
for (SetupAuditTrail t : [ | |
SELECT display, section | |
FROM SetupAuditTrail | |
WHERE createdDate >= :sinceDate | |
ORDER BY createdDate | |
]) { | |
if (!changes.containsKey(t.section)) { | |
changes.put(t.section, new Set<String>()); | |
} | |
changes.get(t.section).add(t.display); | |
} | |
return changes; | |
} | |
DateTime sinceDate(Id sinceTrailId) { | |
try { | |
return [SELECT createdDate FROM SetupAuditTrail WHERE id = :sinceTrailId].createdDate; | |
} catch (Exception e) { | |
return DateTime.now().addYears(-5); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment