You need to sign in to do that
Don't have an account?
Justin Staugaitis
execution of BeforeInsert caused by: System.NullPointerException:
I need help changing my APEX trigger Im getting the following error message
MassLeadConverterControllerTest
massLeadTest
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Health_Score_Calculation_New: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.Health_Score_Calculation_New: line 12, column 1: []
Stack Trace: Class.MassLeadConverterControllerTest.massLeadTest: line 11, column 1
Below is the Trigger
trigger Health_Score_Calculation_New on Account (before insert) {
if(Trigger.isBefore)
{
if (Trigger.isInsert || Trigger.isUpdate)
{
for(Account cob : trigger.new)
{
cob.Score__c = (cob.Implementation__c * 0.15) +
(cob.Migration_In_Progress__c * 0.20) +
(cob.Days_With_No_Activity__c * 0.15) +
(cob.Contact_New_Rollup__c * 0.15) +
(cob.Contact_Left_Rollup__c * 0.15) +
(cob.Issues__c * 0.20) ;
}
}
}
}
MassLeadConverterControllerTest
massLeadTest
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Health_Score_Calculation_New: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.Health_Score_Calculation_New: line 12, column 1: []
Stack Trace: Class.MassLeadConverterControllerTest.massLeadTest: line 11, column 1
Below is the Trigger
trigger Health_Score_Calculation_New on Account (before insert) {
if(Trigger.isBefore)
{
if (Trigger.isInsert || Trigger.isUpdate)
{
for(Account cob : trigger.new)
{
cob.Score__c = (cob.Implementation__c * 0.15) +
(cob.Migration_In_Progress__c * 0.20) +
(cob.Days_With_No_Activity__c * 0.15) +
(cob.Contact_New_Rollup__c * 0.15) +
(cob.Contact_Left_Rollup__c * 0.15) +
(cob.Issues__c * 0.20) ;
}
}
}
}
Check for the not null values and add it as sblow below
Or if the value is null then assign to zero