Created
July 1, 2019 13:19
-
-
Save lfreeland/484423135275cc92978ba9fd74d90d14 to your computer and use it in GitHub Desktop.
OCR Service Apex Class
This file contains 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
public without sharing class OCRService { | |
public void runOCRRollups(List<OpportunityContactRoleChangeEvent> changeEvents) { | |
Set<String> oppContactRoleIds = new Set<String>(); | |
for (OpportunityContactRoleChangeEvent evt : changeEvents) { | |
EventBus.ChangeEventHeader header = evt.ChangeEventHeader; | |
oppContactRoleIds.addAll(new Set<String>(header.recordids)); | |
} | |
// Doesn't fetch deleted Opportunity Contact Roles because | |
// they're not returned from the database despite the "ALL ROWS" | |
// being added. It's as if they're "Purged" instead of soft deleted. | |
// Use scheduled DLRS to compensate. | |
List<OpportunityContactRole> oppContactRoles = | |
[SELECT Id, | |
OpportunityId, | |
ContactId | |
FROM OpportunityContactRole | |
WHERE Id in :oppContactRoleIds | |
ALL ROWS]; | |
// Runs the Developer Opportunity Contact Role Declarative Lookup Rollup Summaries | |
List<SObject> parentRecordsToUpdate = dlrs.RollupService.rollup(oppContactRoles); | |
if (parentRecordsToUpdate.size() > 0) { | |
update parentRecordsToUpdate; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment