Advertisement
SoniaMilena

EmploymentHistoryTriggerHelper-25-06-2019

Jun 25th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. public class EmploymentHistoryTriggerHelper {
  2. public void contactEmploymentHistory(List<Employment_History__c> newRecords, map<Id,Employment_History__c>oldMap){
  3. system.debug('newRecords'+newRecords);
  4. system.debug('oldMap'+oldMap);
  5. Set<Id> empHistorySet = new Set<Id>();
  6.  
  7. system.debug('empHistorySet'+empHistorySet);
  8.  
  9. List<Employment_History__c> historyEmp = [SELECT Id, Cargo__c,Company_Name__c,Contact_Name__c,
  10. End_Date__c,start_Date__c
  11. FROM Employment_History__c
  12. WHERE Contact_Name__c =: newRecords[0].Contact_Name__c];
  13. system.debug('historyEmp'+historyEmp);
  14. Date startMayor;
  15. Date endMayor;
  16. Integer newDate;
  17. boolean primeraIteracion = true;
  18. for (Employment_History__c empl : historyEmp){
  19. if (primeraIteracion){
  20. startMayor = empl.start_Date__c;
  21. primeraIteracion= false;
  22. continue;
  23. }
  24.  
  25. if (empl.start_Date__c > startMayor){
  26. startMayor = empl.start_Date__c;
  27. }
  28.  
  29. system.debug('startMayor Fecha Mayor :'+startMayor);
  30. }
  31.  
  32. system.debug('startMayor Fecha Mayor :'+startMayor);
  33. primeraIteracion = true;
  34.  
  35. for (Employment_History__c empl : historyEmp){
  36. if (primeraIteracion){
  37. endMayor = empl.End_Date__c;
  38. primeraIteracion= false;
  39. continue;
  40. }
  41.  
  42. if (empl.End_Date__c > endMayor){
  43. endMayor = empl.End_Date__c;
  44. }
  45. system.debug('endMayor Fecha menor :'+endMayor);// null
  46. }
  47. system.debug('endMayor Fecha menor :'+endMayor);
  48.  
  49. for(Employment_History__c tempEmp : newRecords){
  50.  
  51. system.debug('tempEmp :'+tempEmp);
  52. if (oldMap != null){// update
  53. Employment_History__c oldEmpl = oldMap != null ? oldMap.get(tempEmp.Id): null;
  54. /*if(oldEmpl.End_Date__c >= oldEmpl.start_date){
  55. tempEmp.addError('digitar una fecha mayor al start Date');
  56. if (oldEmpl.End_Date__c != tempEmp.start_Date__c ){
  57. for(Employment_History__c newStart : historyEmp){
  58. if (newStart.End_Date__c == oldEmpl.End_Date__c){
  59. newStart.End_Date__c = tempEmp.start_Date__c;
  60. }
  61. system.debug('newStart Fecha Mayor :'+newStart);
  62. }
  63. }
  64. //}/*
  65. //1. editar campo
  66. //2. cambiar fecha star_date que se encuentra en ultimo registro "StartMayor"
  67. //3. antes de guardar el start_date debe ingresar al fecha old end_date y
  68. //cambiar la fecha por la nueva edita en start_date
  69. //ver fecha endDate y
  70. //si hay informacion debe cambiar a la fecha modificada en stardate*/
  71. }
  72. if(tempEmp.start_Date__c <= startMayor){//before Insert .addError('Overlap Session')
  73. tempEmp.addError('digitar una fecha mayor al start Date');
  74. system.debug('newRecords :' + newRecords);
  75. system.debug('tempEmp.start_Date__c :'+tempEmp.start_Date__c);
  76. }
  77. if (tempEmp.start_Date__c >=startMayor ){
  78. for (Employment_History__c newEnd : historyEmp){
  79. if (newEnd.End_Date__c == null){
  80. newEnd.End_Date__c = tempEmp.start_Date__c;
  81. }
  82. system.debug('newEnd Fecha Mayor :'+newEnd);
  83.  
  84. }
  85. }
  86.  
  87. }
  88. update historyEmp;
  89. system.debug('historyEmp'+historyEmp);
  90. //update newRecords; no puedo actualizar la lista newRecords porque da error
  91. //system.debug('newRecords :'+newRecords);
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement