function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Travis WrightTravis Wright 

APEX Code help - Check if Number field is Blank or Null

I have a trigger and have to change the logic a little check if a number field is Null. I have done some research and everything is telling me to use the IsNull Fuction and it keep getting the error below and Can't figure it out. I have the section of code that is giving me the issue. 

Error Error: Compile Error: Method does not exist or incorrect signature: IsNull(Decimal) at line 3 column 4

trigger AssignTerritoryType on Account (Before insert, Before update) {
    For (Account a :trigger.new){
if(IsNull(a.Fortune_1000_Rank__c) && (a.NumberOfEmployees >= 10000) && (a.Industry != 'Education')==True  ||
   IsNull(a.Fortune_1000_Rank__c) && (a.AnnualRevenue >= 800000000) && (a.Industry != 'Education')==True  ||
    a.Industry == 'Energy' ||
    a.Industry == 'Pharma/BioTech' ||
    a.Industry == 'Fed - Gov'  ||
    a.Fortune_1000_Rank__c <=650 )
    {
  a.Major__c=true;
  a.Mid__c=False;
  a.Inside__c=False;
  a.Inside_small__c=False;
    }
Best Answer chosen by Travis Wright
Sonam_SFDCSonam_SFDC
Try to use if((a.Fortune_1000_Rank__c == NULL)&&... instead of the ISNULL()

All Answers

Sonam_SFDCSonam_SFDC
Try to use if((a.Fortune_1000_Rank__c == NULL)&&... instead of the ISNULL()
This was selected as the best answer
jsnyderjsnyder
There's no isNull() method for the Decimal class.  http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_decimal.htm#apex_System_Decimal_methods
Vijayendra PatilVijayendra Patil
if(myDecimal != null && String.valueOf(myDecimal).trim() != '')
{ // Do something if the decimal variable is not null and not blank }

In this condition, the first part checks if the decimal variable is not null using the != null comparison operator. The second part checks if the decimal variable is not blank using the String.valueOf() method to convert the decimal value to a string, and then trimming any whitespace characters using the trim() method, before comparing it to an empty string using the != operator.