I am getting below error..
Error:Apex trigger UpdateOverallHealth caused an unexpected exception, contact your administrator: UpdateOverallHealth: execution of BeforeUpdate caused by: System.NullPointerException: Argument cannot be null.
I am posting only relevant part of the code here... Error is coming from.. Decimal health1 = (sc.Health_Calc__c*weightFactor)/12 ;
trigger UpdateOverallHealth on Scorecard__c (after insert,after update,after delete,before insert, before update) {
Map<Id,Opportunity> mapOpportunitiesToUpdate = new Map<Id,Opportunity>();
Map<Id,Release__c> mapReleaseToUpdate = new Map<Id,Release__c>();
WeightFactor__c wt = WeightFactor__c.getInstance();
decimal weightFactor = wt.Factor__c;
if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isbefore){
for(Scorecard__c sc :trigger.new){
String ov_health_workflowrule = null;
if(sc.Scope__c!=null && sc.sch__c!=null && sc.res__c!=null && sc.Risk__c!=null){
if(sc.Health_Calc__c !=null && sc.Health_Calc__c!=0){
Decimal health1 = (sc.Health_Calc__c*weightFactor)/12 ;
Decimal health = health1.setScale(2);
if(health>= 0.80 && health<=1.0){
ov_health_workflowrule='Green';
}
if(health>= 0.60 && health<0.80){
ov_health_workflowrule='Yellow';
}
if(health > 0 && health <0.60){
ov_health_workflowrule='Red';
}
}
}
sc.ov_health_workflowrule__c = ov_health_workflowrule;
Can anyone please tell me why I am getting this error. This error didnot come up for previous 5 records created on Scorecard object , but occurred with the 6th.
Any help would be appreciated.
Thanks!