Advertisement
SoniaMilena

EmploymentHistoryTriggerHelper-27-06-2019

Jun 27th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 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.  
  6. Set<Id> contactIdSet = new Set<Id>();
  7.  
  8. for(Employment_History__c tempRecords : newRecords ){
  9. contactIdSet.add(tempRecords.Contact_Name__c);
  10. system.debug('tempRecords :' + tempRecords);
  11. system.debug('contactIdSet :' + contactIdSet);
  12.  
  13. }
  14. system.debug('emplIdSet :' + contactIdSet);
  15. List<Employment_History__c> idEmpl = [ SELECT Id,Company_Name__c,Contact_Name__c,End_Date__c,
  16. start_Date__c
  17. FROM Employment_History__c WHERE Contact_Name__c =: contactIdSet];
  18. system.debug('idEmpl :' + idEmpl);
  19. map<Id,list<Employment_History__c>> mapEmplList = new map<Id,list<Employment_History__c>> ();
  20. system.debug('mapEmplList :' + mapEmplList);
  21.  
  22. for( Employment_History__c temp : idEmpl){
  23. if(mapEmplList.containsKey(temp.Contact_Name__c)){
  24. mapEmplList.get(temp.Contact_Name__c).add(temp);
  25. system.debug('temp :'+ temp);
  26. }
  27. else{
  28. List<Employment_History__c> listEmpNew = new List<Employment_History__c>();
  29. listEmpNew.add(temp);
  30. mapEmplList.put(temp.Contact_Name__c,listEmpNew);
  31. system.debug('listEmpNew :'+ listEmpNew);
  32. system.debug('temp :'+temp);
  33. }
  34. system.debug('temp :'+temp);
  35.  
  36. }
  37. system.debug('mapEmplList :' + mapEmplList);
  38.  
  39. for(Employment_History__c tempEmp : newRecords){
  40. if(mapEmplList.containsKey(tempEmp.Contact_Name__c)){
  41. //sacar la lista de mi map que esta almacenado mapEmplList
  42. /* esta no se debe realizar ya que , solo puedo ingresar 100
  43. List<Employment_History__c> historyEmp = [SELECT Id, Cargo__c,Company_Name__c,Contact_Name__c,
  44. End_Date__c,start_Date__c
  45. FROM Employment_History__c
  46. WHERE Contact_Name__c =: tempEmp.Contact_Name__c];
  47. system.debug('historyEmp :' + historyEmp); */
  48. for (Employment_History__c newD : mapEmplList.get(tempEmp.Contact_Name__c)){// recorrer la lista historyEmp
  49. if(tempEmp.start_Date__c < newD.End_Date__c && tempEmp.End_Date__c > newD.start_Date__c ){
  50. tempEmp.addError('debe digitar una fecha que se encuentre dentro de un rango posible');
  51. system.debug('newRecords :' + newRecords);
  52. system.debug('newD.End_Date__c :'+newD.End_Date__c);
  53. system.debug('newD.start_Date__c :'+newD.start_Date__c);
  54. system.debug('tempEmp.start_Date__c :'+tempEmp.start_Date__c);
  55. system.debug('tempEmp.start_Date__c :'+tempEmp.End_Date__c);
  56. }
  57. system.debug('newD :'+newD);
  58. }
  59. system.debug('tempEmp :'+tempEmp);
  60. }
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement