Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EmploymentHistoryTriggerHelper {
- public void contactEmploymentHistory(List<Employment_History__c> newRecords, map<Id,Employment_History__c>oldMap){
- system.debug('newRecords'+newRecords);
- system.debug('oldMap'+oldMap);
- Set<Id> contactIdSet = new Set<Id>();
- for(Employment_History__c tempRecords : newRecords ){
- contactIdSet.add(tempRecords.Contact_Name__c);
- system.debug('tempRecords :' + tempRecords);
- system.debug('contactIdSet :' + contactIdSet);
- }
- system.debug('emplIdSet :' + contactIdSet);
- List<Employment_History__c> idEmpl = [ SELECT Id,Company_Name__c,Contact_Name__c,End_Date__c,
- start_Date__c
- FROM Employment_History__c WHERE Contact_Name__c =: contactIdSet];
- system.debug('idEmpl :' + idEmpl);
- map<Id,list<Employment_History__c>> mapEmplList = new map<Id,list<Employment_History__c>> ();
- system.debug('mapEmplList :' + mapEmplList);
- for( Employment_History__c temp : idEmpl){
- if(mapEmplList.containsKey(temp.Contact_Name__c)){
- mapEmplList.get(temp.Contact_Name__c).add(temp);
- system.debug('temp :'+ temp);
- }
- else{
- List<Employment_History__c> listEmpNew = new List<Employment_History__c>();
- listEmpNew.add(temp);
- mapEmplList.put(temp.Contact_Name__c,listEmpNew);
- system.debug('listEmpNew :'+ listEmpNew);
- system.debug('temp :'+temp);
- }
- system.debug('temp :'+temp);
- }
- system.debug('mapEmplList :' + mapEmplList);
- for(Employment_History__c tempEmp : newRecords){
- if(mapEmplList.containsKey(tempEmp.Contact_Name__c)){
- //sacar la lista de mi map que esta almacenado mapEmplList
- /* esta no se debe realizar ya que , solo puedo ingresar 100
- List<Employment_History__c> historyEmp = [SELECT Id, Cargo__c,Company_Name__c,Contact_Name__c,
- End_Date__c,start_Date__c
- FROM Employment_History__c
- WHERE Contact_Name__c =: tempEmp.Contact_Name__c];
- system.debug('historyEmp :' + historyEmp); */
- for (Employment_History__c newD : mapEmplList.get(tempEmp.Contact_Name__c)){// recorrer la lista historyEmp
- if(tempEmp.start_Date__c < newD.End_Date__c && tempEmp.End_Date__c > newD.start_Date__c ){
- tempEmp.addError('debe digitar una fecha que se encuentre dentro de un rango posible');
- system.debug('newRecords :' + newRecords);
- system.debug('newD.End_Date__c :'+newD.End_Date__c);
- system.debug('newD.start_Date__c :'+newD.start_Date__c);
- system.debug('tempEmp.start_Date__c :'+tempEmp.start_Date__c);
- system.debug('tempEmp.start_Date__c :'+tempEmp.End_Date__c);
- }
- system.debug('newD :'+newD);
- }
- system.debug('tempEmp :'+tempEmp);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement