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,
- RecordTypeId, RecordType.name 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);
- /* list<RecordType> gruopRecordType= [SELECT Id, name, SObjectType FROM RecordType
- WHERE SObjectType = 'Employment_History__c' ORDER BY Id ];
- system.debug('Record Types gruopRecordType :' + gruopRecordType.size());
- Map<String,Schema.RecordTypeInfo> rtMapEmplByName = Schema.SObjectType.Employment_History__c.getRecordTypeInfosByName();
- id recordTypeName = rtMapEmplByName.get('Old Employer').getRecordTypeId();
- system.debug('rtMapEmplByName :'+rtMapEmplByName); */
- for(Employment_History__c tempEmp : newRecords){
- //generar if para "tempEmp.record Type == ('Current crEmployer')|| tempEmp.record Type == ('Old Employer'"
- if( tempEmp.recordType.Name == 'Old Employer'){
- 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,
- system.debug('historyEmp :' + historyEmp); */
- for (Employment_History__c oldD : mapEmplList.get(tempEmp.Contact_Name__c)){// recorrer la lista historyEmp
- if(tempEmp.start_Date__c < oldD.End_Date__c && tempEmp.End_Date__c > oldD.start_Date__c ){
- tempEmp.addError('debe digitar una fecha que se encuentre dentro de un rango posible');
- system.debug('mapEmplList :' + mapEmplList);
- system.debug('newRecords :' + newRecords);
- system.debug('oldD.End_Date__c :'+oldD.End_Date__c);
- system.debug('oldD.start_Date__c :'+oldD.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('oldD :'+oldD);
- }
- system.debug('tempEmp :'+tempEmp);
- }
- }
- else if(tempEmp.RecordType.Name =='Current Employer' ){
- //if(Employment_History__c.getRecordTypeId('Current Employer')){
- system.debug('tempEmp.Id :'+tempEmp.name);
- if(mapEmplList.containsKey(tempEmp.Contact_Name__c)){
- for(Employment_History__c currentD : mapEmplList.get(tempEmp.Contact_Name__c)){
- system.debug('mapEmplList :' + mapEmplList);
- if(tempEmp.start_Date__c >= currentD.End_Date__c ){
- tempEmp.addError('debe digitar una fecha que se encuentre dentro de un rango posible');
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement