1

In my below code I am getting error as Illegal integer.

public void refedgeAnnualrevenue(list<Account> newAccts){
        for(Account ac : newAccts){
            if(ac.AnnualRevenue >= 0 && ac.AnnualRevenue <=49999999){
                ac.RefEdge_Annual_Revenue__c ='< $50M';
            } else if(ac.AnnualRevenue >= 50000000 && ac.AnnualRevenue <=499999999){
                ac.RefEdge_Annual_Revenue__c ='$50M-$500M';
            }else if(ac.AnnualRevenue >= 500000000 && ac.AnnualRevenue <=999999999){
                ac.RefEdge_Annual_Revenue__c ='$500M - $1B';
            }else if(ac.AnnualRevenue >= 1000000000  && ac.AnnualRevenue <=4999999999){
               ac.RefEdge_Annual_Revenue__c= '$1B - $5B';
            }else if(ac.AnnualRevenue >= 5000000000){
                ac.RefEdge_Annual_Revenue__c ='> $5B';
            }
        } 
    }

at the last two if else only.

Please help to fix this issue. Thank you.

1

Account.AnnualRevenue is soaptype: xsd:double and is a field of type Currency with precision (18,0). Normally, in Apex one would treat these as Decimals so you would have:

public void refedgeAnnualrevenue(list<Account> newAccts){
        for(Account ac : newAccts){
            if(ac.AnnualRevenue >= 0 && ac.AnnualRevenue <=49999999.0){
                ac.RefEdge_Annual_Revenue__c ='< $50M';
            } else if(ac.AnnualRevenue >= 50000000.0 && ac.AnnualRevenue <=499999999.0){
                ac.RefEdge_Annual_Revenue__c ='$50M-$500M';
            }else if(ac.AnnualRevenue >= 500000000.0 && ac.AnnualRevenue <=999999999.0){
                ac.RefEdge_Annual_Revenue__c ='$500M - $1B';
            }else if(ac.AnnualRevenue >= 1000000000.0  && ac.AnnualRevenue <=4999999999.0){
               ac.RefEdge_Annual_Revenue__c= '$1B - $5B';
            }else if(ac.AnnualRevenue >= 5000000000.0){
                ac.RefEdge_Annual_Revenue__c ='> $5B';
            }
        } 
    }

So, the comparand should be expressed as a decimal constant (adding the .0 to the integer in your OP).

Integers are limited in magnitude to +/- 2,147,483,647 (i.e. 2E31 -1)

1

Your AnnualRevenue overflows Integer data type, just add L after your integers in if-clauses like this, it will automatically cast them to Long:

if (ac.AnnualRevenue >= 1000000000L && ac.AnnualRevenue <= 4999999999L)

Note: add L to all integers in comparison.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.