Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lfreeland/484423135275cc92978ba9fd74d90d14 to your computer and use it in GitHub Desktop.
Save lfreeland/484423135275cc92978ba9fd74d90d14 to your computer and use it in GitHub Desktop.
OCR Service Apex Class
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