Guest User

Untitled

a guest
Oct 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. public static void UpdateCertifiedStatus(Set<Id> newUpdatesIds)
  2. {
  3. Map<Id, String> certRenews = new Map<Id, String>();
  4. Map<Id, String> updateCerts = new Map<Id, String>();
  5. List<Certification_in_Specialized_Ministry__c> certs = new List<Certification_in_Specialized_Ministry__c>();
  6. Set<Id> certIds = new Set<Id>();
  7.  
  8. Id lastId = null;
  9. Integer highestYear = -1;
  10. Integer lastYear = 0;
  11. String renewalStatus = null;
  12.  
  13. for(Certification_Updates__c up : [SELECT Id, Education_Certification__c FROM Certification_Updates__c WHERE Id IN :newUpdatesIds]) {
  14. certIds.add(up.Education_Certification__c);
  15. }
  16.  
  17. 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]) {
  18. if(lastId != updateRenew.Education_Certification__c && lastId != null) {
  19. updateCerts.put(lastId, renewalStatus);
  20. highestYear = -1;
  21. }
  22.  
  23. lastYear = (updateRenew.Year__c == null || updateRenew.Year__c.length() == 0) ? 0 : Integer.valueOf(updateRenew.Year__c);
  24.  
  25. if(lastYear > highestYear) {
  26. highestYear = lastYear;
  27. renewalStatus = updateRenew.Certification_Renewal_Status__c;
  28. }
  29.  
  30. lastId = updateRenew.Education_Certification__c;
  31. }
  32.  
  33. 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()]) {
  34. String status = updateCerts.get(cert.Id);
  35. cert.EC_Certification_Renewal_Status__c = status;
  36. certs.add(cert);
  37. }
  38.  
  39. if(certs.size() > 0) {
  40. update certs;
  41. }
  42. }
Add Comment
Please, Sign In to add comment