Guest User

Untitled

a guest
Feb 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. Public with sharing class InspectionQuotasHandler{
  2.  
  3. public static void UpdateMonthlyQuotaOfInspection(List<Inspection__c> InspectionQuotasList){
  4.  
  5. Set<id> AccountId = new Set<Id>();
  6.  
  7. for (Inspection__c i : (List<Inspection__c>)Trigger.new) {
  8. AccountId.add(i.Franchise__c);
  9. }
  10.  
  11. Map<String,map<String,Id>> keyByLookupMap = new Map<String,map<String,Id>>();
  12.  
  13. for(Monthly_Quota__c mq : [SELECT Id, Name,Account__c
  14. FROM Monthly_Quota__c
  15. WHERE Account__c = :AccountId]){
  16.  
  17. if(!keyByLookupMap.containsKey(mq.Account__c))
  18. keyByLookupMap.put(mq.Account__c, new map<String,Id>());
  19. keyByLookupMap.get(mq.Account__c).put(mq.Name,mq.Id);
  20.  
  21. }
  22.  
  23. if(!keyByLookupMap.isEmpty()){
  24. for(Inspection__c i : (List<Inspection__c>)trigger.new){
  25. if(i.Inspection_Date__c != null && keyByLookupMap.containsKey(mq.Account__c) && keyByLookupMap.get(mq.Account__c).containsKey(convertMonthToWord(i.Inspection_Date__c.month()))){
  26. if(i.Status__c == 'Completed' && i.Month_Since_Launch__c > 0){
  27. i.Monthly_Quota__c = keyByLookupMap.get(mq.Account__c).get(convertMonthToWord(i.Inspection_Date__c.month()));
  28. }
  29. }
  30. }
  31. }
  32. }
  33.  
  34. public static String convertMonthToWord(Integer monthIndex){
  35.  
  36. if(monthIndex==1){
  37. return 'January';
  38. }else if(monthIndex==2){
  39. return 'February';
  40. }else if(monthIndex==3){
  41. return 'March';
  42. }else if(monthIndex==4){
  43. return 'April';
  44. }else if(monthIndex==5){
  45. return 'May';
  46. }else if(monthIndex==6){
  47. return 'June';
  48. }else if(monthIndex==7){
  49. return 'July';
  50. }else if(monthIndex==8){
  51. return 'August';
  52. }else if(monthIndex==9){
  53. return 'September';
  54. }else if(monthIndex==10){
  55. return 'October';
  56. }else if(monthIndex==11){
  57. return 'November';
  58. }else if(monthIndex==12){
  59. return 'December';
  60. }else{
  61. return null;
  62. }
  63.  
  64. }
Add Comment
Please, Sign In to add comment