[SalesForce] Illegal Integer but only after threshold

We are deploying a tiered schedule for pricing related to products based on a firms assets under management. The tiers have breakpoints based on these aum fields (currency).

In apex I have a method for building tier schedules, which works fine until I hit the $3B entry breakpoint. When I run the method at this breakpoint, I get a message in the developer console about an 'Illegal Integer'.

The Apex Method that I have accepts the following parameters and then processes the new tier schedules:

public static List<rbTier__c> createTiers(Id productFamilyId, Integer batchSize, Decimal beginningAUM, decimal aumIncrement, Decimal beginningBasePrice, Decimal basePriceIncrement)
{
    List<rbTier__c> tierList = new List<rbTier__c>();
    List<rbTierFamily__c> familyList = [Select Id, Name, RB_Product__c From rbTierFamily__c WHere Id = :productFamilyId];
    List<rbTier__c> existingTiers = getTiersForFamilies(familyList);
    Integer sequence = 0;
    INteger plusOne = 1;
    Integer minusOne = -1;
    Decimal aumFloor = beginningAUM;
    Decimal aumCeiling = aumFloor + aumIncrement + minusOne;
    if(existingTiers.size() > 0)
    {
        sequence = existingTiers.size() + plusOne;
    }
    else
    {
        sequence = 1;
    }
    for(Integer i = 0;i < batchSize; i++)
    {
        if(sequence == 1)
        {
            rbTier__c t = new rbTier__c();
            t.AUM_Floor__c = aumFloor;
            t.AUM_Ceiling__c = beginningAUM + aumIncrement;
            t.Sequence__c = sequence + (1 * i);
            t.Name = 'Tier '+ String.valueOf(sequence + (1 * i));
            t.Base_Amount__c = beginningBasePrice + (basePriceIncrement * i);
            t.RB_Tier_Family__c = productFamilyId;
            tierList.add(t);
            aumFloor = aumCeiling + plusOne;
            aumCeiling = aumFloor + aumIncrement + minusOne;
        }
        else
        {
            System.debug('aum floor entering loop is '+aumFloor+ ' and aum ceiling entering is '+ aumCeiling);
            rbTier__c t = new rbTier__c();
            t.AUM_Floor__c = aumFloor;
            t.AUM_Ceiling__c = aumCeiling;
            t.Sequence__c = sequence + (1 * i);
            t.Name = 'Tier '+ String.valueOf(sequence + (1 * i));
            t.Base_Amount__c = beginningBasePrice + (basePriceIncrement * i);
            t.RB_Tier_Family__c = productFamilyId;
            tierList.add(t);
            aumFloor = aumCeiling + plusOne;
            aumCeiling = aumFloor + aumIncrement + minusOne;
            System.debug('aum floor exiting loop is '+aumFloor+ ' and aum ceiling exiting is '+ aumCeiling + ' and AUM increment is '+ aumIncrement);

        }
    }
    if(tierList.size() > 0)
    {
        try 
        {
            RBS_GlobalDMLHandler.insertObjectList(tierList);    
        } 
        catch(Exception ex) 
        {
            System.debug('Problem encountered inserting the tier batch | '+ex.getMessage());
        }
    }
    return tierList;
}

I ran this in from the developer console in stages as outlined here:
(note the Id is hardcoded only for the purposes of testing)

RBS_TierHelper.createTiers('a184B000000xdd9QAA', 1, 0, 99999999, 10000, 0);
RBS_TierHelper.createTiers('a184B000000xdd9QAA', 8, 100000000, 50000000, 11250, 1250);
RBS_TierHelper.createTiers('a184B000000xdd9QAA', 5, 500000000, 100000000, 22500, 2500);
RBS_TierHelper.createTiers('a184B000000xdd9QAA', 8, 1000000000, 250000000, 35000, 2500);
RBS_TierHelper.createTiers('a184B000000xdd9QAA', 4, 3000000000, 500000000, 55000, 5000);

The outputs for the first four traunches generate results as expected. The fifth traunch, beginning at $3,000,000,000 returns an error from the dev console; 'Line 7, Column 53 Illegal Integer'.

Does anyone know what is going wrong here?

Thanks in advance for any insight you can provide!

Best Answer

Integers in Salesforce are signed, 32-bit (and 2's compliment, I assume)

The maximum value that can be held in an Integer type is therefore (2^31) - 1 = 2,147,483,647

If you need to work with values larger than that, then you'll need to use the Long type instead of Integer