Advertisement
SoniaMilena

Error

Jul 2nd, 2019
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 4.95 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,start_Date__c,
  16.                                                RecordTypeId, RecordType.name FROM Employment_History__c
  17.                                                WHERE Contact_Name__c =: contactIdSet];
  18.         system.debug('idEmpl :' + idEmpl);
  19.        
  20.         map<Id,list<Employment_History__c>> mapEmplList = new  map<Id,list<Employment_History__c>> ();
  21.         system.debug('mapEmplList :' + mapEmplList);
  22.  
  23.         for( Employment_History__c temp : idEmpl){
  24.             if(mapEmplList.containsKey(temp.Contact_Name__c)){
  25.             mapEmplList.get(temp.Contact_Name__c).add(temp);
  26.             system.debug('temp :'+ temp);                
  27.             }
  28.             else{
  29.                 List<Employment_History__c> listEmpNew = new List<Employment_History__c>();
  30.                 listEmpNew.add(temp);
  31.                 mapEmplList.put(temp.Contact_Name__c,listEmpNew);
  32.                 system.debug('listEmpNew :'+ listEmpNew);
  33.                 system.debug('temp :'+temp);
  34.             }
  35.         system.debug('temp :'+temp);      
  36.         }
  37.         system.debug('mapEmplList :' + mapEmplList);  
  38.        /* list<RecordType> gruopRecordType= [SELECT Id, name, SObjectType FROM RecordType
  39.                                            WHERE SObjectType = 'Employment_History__c' ORDER BY Id ];
  40.         system.debug('Record Types gruopRecordType :' + gruopRecordType.size());
  41.         Map<String,Schema.RecordTypeInfo> rtMapEmplByName = Schema.SObjectType.Employment_History__c.getRecordTypeInfosByName();
  42.         id recordTypeName = rtMapEmplByName.get('Old Employer').getRecordTypeId();
  43.         system.debug('rtMapEmplByName :'+rtMapEmplByName); */
  44.         for(Employment_History__c tempEmp : newRecords){
  45.             //generar if para "tempEmp.record Type == ('Current crEmployer')|| tempEmp.record Type == ('Old Employer'"          
  46.             if( tempEmp.recordType.Name == 'Old Employer'){    
  47.                    
  48.                 if(mapEmplList.containsKey(tempEmp.Contact_Name__c)){
  49.                     /*sacar la lista de mi map que esta almacenado mapEmplList
  50.                      esta no se debe realizar ya que , solo puedo ingresar 100
  51.                     List<Employment_History__c> historyEmp = [SELECT Id, Cargo__c,Company_Name__c,Contact_Name__c,
  52.                     system.debug('historyEmp :' + historyEmp);  */
  53.                     for (Employment_History__c oldD : mapEmplList.get(tempEmp.Contact_Name__c)){// recorrer la lista historyEmp
  54.                             if(tempEmp.start_Date__c < oldD.End_Date__c && tempEmp.End_Date__c > oldD.start_Date__c ){
  55.                                 tempEmp.addError('debe digitar una fecha que se encuentre dentro de un rango posible');
  56.                                 system.debug('mapEmplList :' + mapEmplList);
  57.                                 system.debug('newRecords :' + newRecords);
  58.                                 system.debug('oldD.End_Date__c :'+oldD.End_Date__c);
  59.                                 system.debug('oldD.start_Date__c :'+oldD.start_Date__c);
  60.                                 system.debug('tempEmp.start_Date__c :'+tempEmp.start_Date__c);
  61.                                 system.debug('tempEmp.start_Date__c :'+tempEmp.End_Date__c);
  62.                             }
  63.                             system.debug('oldD :'+oldD);
  64.                         }
  65.                     system.debug('tempEmp :'+tempEmp);
  66.                     }
  67.                 }    
  68.            
  69.             else if(tempEmp.RecordType.Name =='Current Employer' ){
  70.                 //if(Employment_History__c.getRecordTypeId('Current Employer')){
  71.                     system.debug('tempEmp.Id :'+tempEmp.name);
  72.                 if(mapEmplList.containsKey(tempEmp.Contact_Name__c)){
  73.                     for(Employment_History__c currentD : mapEmplList.get(tempEmp.Contact_Name__c)){
  74.                             system.debug('mapEmplList :' + mapEmplList);
  75.                         if(tempEmp.start_Date__c >= currentD.End_Date__c  ){
  76.                                 tempEmp.addError('debe digitar una fecha que se encuentre dentro de un rango posible');
  77.                            
  78.                         }
  79.                     }
  80.                 }    
  81.             }        
  82.                              
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement