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> empHistorySet = new Set<Id>();
- system.debug('empHistorySet'+empHistorySet);
- 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 =: newRecords[0].Contact_Name__c];
- system.debug('historyEmp'+historyEmp);
- Date startMayor;
- Date endMayor;
- Integer newDate;
- boolean primeraIteracion = true;
- for (Employment_History__c empl : historyEmp){
- if (primeraIteracion){
- startMayor = empl.start_Date__c;
- primeraIteracion= false;
- continue;
- }
- if (empl.start_Date__c > startMayor){
- startMayor = empl.start_Date__c;
- }
- system.debug('startMayor Fecha Mayor :'+startMayor);
- }
- system.debug('startMayor Fecha Mayor :'+startMayor);
- primeraIteracion = true;
- for (Employment_History__c empl : historyEmp){
- if (primeraIteracion){
- endMayor = empl.End_Date__c;
- primeraIteracion= false;
- continue;
- }
- if (empl.End_Date__c > endMayor){
- endMayor = empl.End_Date__c;
- }
- system.debug('endMayor Fecha menor :'+endMayor);// null
- }
- system.debug('endMayor Fecha menor :'+endMayor);
- for(Employment_History__c tempEmp : newRecords){
- system.debug('tempEmp :'+tempEmp);
- if (oldMap != null){// update
- Employment_History__c oldEmpl = oldMap != null ? oldMap.get(tempEmp.Id): null;
- /*if(oldEmpl.End_Date__c >= oldEmpl.start_date){
- tempEmp.addError('digitar una fecha mayor al start Date');
- if (oldEmpl.End_Date__c != tempEmp.start_Date__c ){
- for(Employment_History__c newStart : historyEmp){
- if (newStart.End_Date__c == oldEmpl.End_Date__c){
- newStart.End_Date__c = tempEmp.start_Date__c;
- }
- system.debug('newStart Fecha Mayor :'+newStart);
- }
- }
- //}/*
- //1. editar campo
- //2. cambiar fecha star_date que se encuentra en ultimo registro "StartMayor"
- //3. antes de guardar el start_date debe ingresar al fecha old end_date y
- //cambiar la fecha por la nueva edita en start_date
- //ver fecha endDate y
- //si hay informacion debe cambiar a la fecha modificada en stardate*/
- }
- if(tempEmp.start_Date__c <= startMayor){//before Insert .addError('Overlap Session')
- tempEmp.addError('digitar una fecha mayor al start Date');
- system.debug('newRecords :' + newRecords);
- system.debug('tempEmp.start_Date__c :'+tempEmp.start_Date__c);
- }
- if (tempEmp.start_Date__c >=startMayor ){
- for (Employment_History__c newEnd : historyEmp){
- if (newEnd.End_Date__c == null){
- newEnd.End_Date__c = tempEmp.start_Date__c;
- }
- system.debug('newEnd Fecha Mayor :'+newEnd);
- }
- }
- }
- update historyEmp;
- system.debug('historyEmp'+historyEmp);
- //update newRecords; no puedo actualizar la lista newRecords porque da error
- //system.debug('newRecords :'+newRecords);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement