Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void UpdateCertifiedStatus(Set<Id> newUpdatesIds)
- {
- Map<Id, String> certRenews = new Map<Id, String>();
- Map<Id, String> updateCerts = new Map<Id, String>();
- List<Certification_in_Specialized_Ministry__c> certs = new List<Certification_in_Specialized_Ministry__c>();
- Set<Id> certIds = new Set<Id>();
- Id lastId = null;
- Integer highestYear = -1;
- Integer lastYear = 0;
- String renewalStatus = null;
- for(Certification_Updates__c up : [SELECT Id, Education_Certification__c FROM Certification_Updates__c WHERE Id IN :newUpdatesIds]) {
- certIds.add(up.Education_Certification__c);
- }
- for(Certification_Updates__c updateRenew : [SELECT Id, Certification_Renewal_Status__c, Year__c, Education_Certification__c FROM Certification_Updates__c WHERE Education_Certification__c IN :certIds ORDER BY Education_Certification__c, CreatedDate]) {
- if(lastId != updateRenew.Education_Certification__c && lastId != null) {
- updateCerts.put(lastId, renewalStatus);
- highestYear = -1;
- }
- lastYear = (updateRenew.Year__c == null || updateRenew.Year__c.length() == 0) ? 0 : Integer.valueOf(updateRenew.Year__c);
- if(lastYear > highestYear) {
- highestYear = lastYear;
- renewalStatus = updateRenew.Certification_Renewal_Status__c;
- }
- lastId = updateRenew.Education_Certification__c;
- }
- for(Certification_in_Specialized_Ministry__c cert : [SELECT Id, EC_Certification_Renewal_Status__c FROM Certification_in_Specialized_Ministry__c WHERE Id IN :updateCerts.keySet()]) {
- String status = updateCerts.get(cert.Id);
- cert.EC_Certification_Renewal_Status__c = status;
- certs.add(cert);
- }
- if(certs.size() > 0) {
- update certs;
- }
- }
Add Comment
Please, Sign In to add comment