
can you try below code and send back the debug log once again, i dont see any issue but just to make sure trigger NewYear on Judgment_Event__c (before insert,before update) {
/*
Since we can not have the correct value of formula fields in before triggers, we need to fire a query to fetch the state information and the record it belongs to.
*/
Set<String> States_Set=new Set<String>();//This is to collect all the states from the records on which the trigger fired.
Map<Id,String>JEStateMap=new Map<Id,String>();//This is to collect the id of JE record and the state it needs to be used
Map<String,Integer>CountyStateYearMap=new Map<String,Integer>();//This is to collect all the information necessary based on State in County record
Map<String,Integer>OtherStateYearMap=new Map<String,Integer>();//This is to collect all the information necessary based on State if other state is selected
Map<String,Integer>SecretaryStateYearMap=new Map<String,Integer>();//This is to collect all the information necessary based on State if secretary state is selected
Map<Id,County__c>CountyInfoMap=new Map<Id,County__c>();//To collect all the information related to county
Set<Id>CountyIds=new Set<Id>();
system.debug('JE Information ***'+Trigger.new);
for(Judgment_Event__c JE: Trigger.new){
if(je.Action_Type__c == 'Recording' ) {
if(JE.Recording_Location__c=='County'){
if(JE.County__c!=Null)
CountyIds.add(JE.County__c);
}
if(JE.Recording_Location__c=='Other State Office' || JE.Recording_Location__c=='Secretary of State'){
if(JE.Recording_Office_State__c!=Null)
States_Set.add(JE.Recording_Office_State__c);
}
}
}// By End of this for loop, we will have the county id information, states from Recording_Office_State__c based on conditions.
system.debug('*** States_Set, CountyIds'+States_Set+'**'+CountyIds);
//Time to query county and get the required state information and add it to our state list
for(County__c countyRecord:[select id,state__r.Name From county__c where id iN :CountyIds]){
CountyInfoMap.put(countyRecord.id,countyRecord);
States_Set.add(countyRecord.state__r.Name);
}
//Now we have all the state information based on conditions, query the Judgment_Exp_Matrix__c and get corresponding year information.
system.debug('*** States_Set, CountyInfoMap'+States_Set+'**'+CountyInfoMap);
for(Judgment_Exp_Matrix__c JEM:[select id,Years__c,Action_Type__c,
Recording_Location__c,State1__c,State1__r.Name,
Recording_Location__c
from Judgment_Exp_Matrix__c where State1__r.Name IN :States_Set]){
if(JEM.Action_Type__c == 'Recording'){
IF(JEM.Recording_Location__c=='County' ) {
if(JEM.Years__c!=Null)
CountyStateYearMap.put(JEM.State1__r.Name,Integer.valueof(JEM.Years__c));
}
If(JEM.Recording_Location__c == 'Other State Office' ) {
if(JEM.Years__c!=Null)
OtherStateYearMap.put(JEM.State1__r.Name,Integer.valueof(JEM.Years__c));
}
If(JEM.Recording_Location__c == 'Secretary of State' ) {
if(JEM.Years__c!=Null)
SecretaryStateYearMap.put(JEM.State1__r.Name,Integer.valueof(JEM.Years__c));
}
}
}// By end of this loop we will have all the information grouped on our conditions, its time to add the years to the Recording_Date__c
system.debug('Maps Coming as'+'**+CountyStateYearMap+'***'+OtherStateYearMap+'***'+SecretaryStateYearMap);
for(Judgment_Event__c JE: Trigger.new){
if(je.Action_Type__c == 'Recording' ) {
if(JE.Recording_Location__c=='County' && JE.County__c!=Null && JE.Recording_Date__c!=Null){
if(CountyStateYearMap.keyset().contains(CountyInfoMap.get(JE.County__c).state__r.Name))
JE.Expiration_Date__c=JE.Recording_Date__c.addYears(CountyStateYearMap.get(CountyInfoMap.get(JE.County__c).state__r.Name));
}
if(JE.Recording_Location__c=='Other State Office' && JE.Recording_Office_State__c!=Null && JE.Recording_Date__c!=Null){
if(OtherStateYearMap.keyset().contains(JE.Recording_Office_State__c))
JE.Expiration_Date__c=JE.Recording_Date__c.addYears(OtherStateYearMap.get(JE.Recording_Office_State__c));
}
if(JE.Recording_Location__c=='Secretary of State'&& JE.Recording_Office_State__c!=Null && JE.Recording_Date__c!=Null ){
if(SecretaryStateYearMap.keyset().contains(JE.Recording_Office_State__c))
JE.Expiration_Date__c=JE.Recording_Date__c.addYears(SecretaryStateYearMap.get(JE.Recording_Office_State__c));
}
}
system.debug('JE Final date for id **'+JE.Id+'***'+JE.Expiration_Date__c);
}// By end of this loop we will have the expiration date populated based on conditions.
system.debug('JE Final INFO ****'+trigger.new);
}
29 answers