You need to sign in to do that
Don't have an account?
sfdc-admin-sm
System.TypeException: Invalid decimal: null
Hello,
I am getting the error System.TypeException: Invalid decimal: null after running a test class. The test class (and others) that is failing is inserting an Account and the error is referencing the line a.Annualized_ACV__c = Decimal.valueOf(str); in the snippet of my before update Account trigger code below:
for(Account a : Trigger.new){
for (AggregateResult ar : lstOpptyAnnualACV){
if(lstOpptyAnnualACV != NULL){
String str = '' + lstOpptyAnnualACV[0].get('sum');
a.Annualized_ACV__c = Decimal.valueOf(str);
}
}
}
Any advice on how to fix this? Note the trigger code is working fine and is updating the Annualized_ACV__c correctly through the UI. The error occurs when running test classes that are inserting Accounts
Thanks
I am getting the error System.TypeException: Invalid decimal: null after running a test class. The test class (and others) that is failing is inserting an Account and the error is referencing the line a.Annualized_ACV__c = Decimal.valueOf(str); in the snippet of my before update Account trigger code below:
for(Account a : Trigger.new){
for (AggregateResult ar : lstOpptyAnnualACV){
if(lstOpptyAnnualACV != NULL){
String str = '' + lstOpptyAnnualACV[0].get('sum');
a.Annualized_ACV__c = Decimal.valueOf(str);
}
}
}
Any advice on how to fix this? Note the trigger code is working fine and is updating the Annualized_ACV__c correctly through the UI. The error occurs when running test classes that are inserting Accounts
Thanks
You can add null check before typecase to make sure that exception will not occer: Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
Thanks for your resonse. I tried your suggestion with the null check but the error still persists. I think the error I am getting is similar to the one discussed at http://christopheralunlewis.blogspot.com/2010/09/converting-decimal-value-to-integer.html however my error is not shown in the VF page as that post mentions but when running a test class.
Any other code suggestions?