You need to sign in to do that
Don't have an account?
prati@salesforce
Trigger Not getting called while deploying trigger and test class to production
Hi
I have a trigger and its test class which runs perfectly fine in the sandbox and it also shows 76 % coverage. I also had some debug statements in both the test class and trigger and I was able to view the expected result. But when I deploy it to production, choosing run specific test classses only, it doesnt get deployed and the error is code coverage is 0. I opened the debug logs and it seems like the trigger is not getting called when test datat is inserted because I only see the debug ststaments from the test class but not from the trigger.
Please help me to find out ehat might be the reason that it is not getting called.... It is very urgent.
Thank you
I have a trigger and its test class which runs perfectly fine in the sandbox and it also shows 76 % coverage. I also had some debug statements in both the test class and trigger and I was able to view the expected result. But when I deploy it to production, choosing run specific test classses only, it doesnt get deployed and the error is code coverage is 0. I opened the debug logs and it seems like the trigger is not getting called when test datat is inserted because I only see the debug ststaments from the test class but not from the trigger.
Please help me to find out ehat might be the reason that it is not getting called.... It is very urgent.
Thank you
trigger ConsecutiveException on Inventory_Exception__c (before insert, before update) {
Set<Id> hierarchyNodeSet = new Set<Id>();
Set<Id> exposureSet = new Set<Id>();
Map<Id, Exposure__c> exposureMap = new Map<Id, Exposure__c>();
Map<id, List<Inventory_exception__c>> inventoryExceptionCriticalityMap = new Map<Id,List<Inventory_exception__c>>();
for(Inventory_Exception__c ie: trigger.new){
exposureSet.add(ie.exposurelookup__c);
}
for(Exposure__c exp: [SELECT id, Hierarchy_Node__c,evaluation_date__c from Exposure__c where Id IN :exposureSet]){
hierarchyNodeSet.add(exp.Hierarchy_Node__c);
exposureMap.put(exp.id, exp);
}
for(Inventory_exception__c ie: [select id,exception_count__c, business__c, exposurelookup__c, exposurelookup__r.evaluation_date__c, exposurelookup__r.Hierarchy_Node__c from Inventory_exception__c where exposurelookup__r.evaluation_date__c = LAST_N_MONTHS:3 AND exposurelookup__r.Hierarchy_Node__c IN :hierarchyNodeSet order by exposurelookup__r.Hierarchy_Node__c, exposurelookup__r.evaluation_date__c desc]){
if(inventoryExceptionCriticalityMap.containsKey(ie.exposurelookup__r.Hierarchy_Node__c))
inventoryExceptionCriticalityMap.get(ie.exposurelookup__r.Hierarchy_Node__c).add(ie);
else
inventoryExceptionCriticalityMap.put(ie.exposurelookup__r.Hierarchy_Node__c, new List<Inventory_exception__c> {ie});
}
Integer countException = 1;
Integer newRecordMonth;
for(Inventory_exception__c ie: trigger.new){
if(exposuremap!=null && exposuremap.size()>0){
//System.debug('Date is '+ie+'\n evaluationDate'+exposureMap.get(ie.exposureLookup__c));
//System.debug('keySet is '+inventoryExceptionCriticalityMap.keyset());
//System.debug('Hierarcchy is'+exposureMap.get(ie.exposureLookup__c).Hierarchy_Node__c);
newRecordMonth = exposureMap.get(ie.exposureLookup__c).evaluation_date__c.month();
ie.exception_count__c = 1;
if(inventoryExceptionCriticalityMap != null && inventoryExceptionCriticalityMap.size()> 0 && inventoryExceptionCriticalityMap.containsKey(exposureMap.get(ie.exposureLookup__c).Hierarchy_Node__c)){
for(Id BUs: inventoryExceptionCriticalityMap.keyset()){
if(exposureMap.get(ie.exposureLookup__c).Hierarchy_Node__c == BUs ){
for(Inventory_exception__c iexp: inventoryExceptionCriticalityMap.get(bus)){
Integer oldRecordMonth = iexp.exposurelookup__r.evaluation_date__c.month();
System.debug('Old record month is'+oldRecordMonth+'\n New record' +newrecordMonth);
if(newRecordMonth - oldRecordMonth == 1)
countException = 2;
else if(((newRecordMonth - oldRecordMonth) == 2) && countException == 2 )
countException = 3;
else if(((newRecordMonth - oldRecordMonth) == 3) && countException == 3)
countException = 4;
}
ie.exception_count__c = countException;
}
}
}
}
}
Here is my test class,
@isTest
public class ConsecutiveExceptionTest {
private static testMethod void test_consecutiveException(){
rkl__RK_Hierarchy_Node__c hierarchy = new rkl__RK_Hierarchy_Node__c();
hierarchy.name= 'ABC';
hierarchy.rkl__Node_Key__c= 'ABC123';
insert hierarchy;
rkl__RK_Hierarchy_Node__c hie =[select name , id, rkl__Node_Key__c from rkl__RK_Hierarchy_Node__c where rkl__Node_Key__c='ABC123' limit 1];
String hierarchyName = [select name , id, rkl__Node_Key__c from rkl__RK_Hierarchy_Node__c where rkl__Node_Key__c='ABC123' limit 1].name;
System.debug('Hierarachy name is :'+hierarchyName);
List<Exposure__c> exposure = new List<Exposure__c>();
for(integer i=0; i<5; i++){
Exposure__c expo = new Exposure__c();
expo.Hierarchy_Node__c = hierarchy.id;
expo.Exception_Occured__c = 'yes';
if(i==0)
expo.Evaluation_Date__c = Date.newInstance(2016, 05, 01);
if(i==1)
expo.Evaluation_Date__c = Date.newInstance(2016, 06, 01);
if(i==2)
expo.Evaluation_Date__c = Date.newInstance(2016, 07, 01);
if(i==3)
expo.Evaluation_Date__c = Date.newInstance(2016, 08, 01);
if(i==4)
expo.Evaluation_Date__c = Date.newInstance(2016, 09, 01);
exposure.add(expo);
}
insert exposure;
List<Exposure__c> exp = [select id, name, Hierarchy_Node__c, Evaluation_Date__c, Exception_Occured__c from Exposure__c where Hierarchy_Node__c= :hie.Id ];
if(exp.size()>0){
for(integer i=0; i<5; i++){
System.debug(exp[i].name);
System.debug(exp[i].Evaluation_Date__c);
}
}
List<Inventory_Exception__c> inventory = new List<Inventory_Exception__c>();
for(integer i=0; i<5; i++){
Inventory_Exception__c inv = new Inventory_Exception__c();
inv.ExposureLookup__c = exposure[i].Id;
inventory.add(inv);
}
insert inventory;
List<Inventory_Exception__c> inven = [select name, id, Exception_Count__c, Date_of_Evaluation__c, ExposureLookup__c from Inventory_Exception__c limit 4];
for(integer i=0; i<4; i++){
System.debug('Inventory exp name is :'+inven[i].name);
System.debug('Consecutive exception is :'+inven[i].Exception_Count__c);
System.debug('Consecutive exception is :'+inven[i].Date_of_Evaluation__c);
}
}
}
1) Is your test class failing during deployment?
2) Have you used (SeeAllData = true) in you test class? If yes, then it is possible there is a difference between sandbox and production data. So, some conditions were not matching resulting low coverage.
3) If it is too urgent, create a dummy class of 2-3 line, write test class for that class and deploy with the trigger. This approach is generally not advisable.
Hope this will help you.
Thanks,
Sumit Kumar Singh
1 and 2 options are not valid in my scenario , it doesnt fail and neiher I am using seeAllData. CAn you plese provide some details for option 3?
You can use followning dummy class to increase the test coverage -
Incluse these classes with the trigger and try to deploy again. Your trigger should get deployed.
Later You find out the issue and deploy the correct test class and delete these both dummy classes from the production.
Thanks,
Sumit Kumar Singh.
Any help will be highly appreciated.