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
sriram anilsriram anil 

Compile Error: Incompatible key type Decimal for Map<Integer,String>


I am creating custom setting Object 1st
in this object Country_barcodes__c two field creating
1is country_phone_code__c---->country phone codes
2nd country barcode---->like Ex:Name:INDIA---->barcode-Ind

i am insert  new record into account
BillingCountry is i am enter india automatically phone field also show phonecode like 91
=========================================================================
Trigger basicTrigger on account(before insert,before update){
    
    if(trigger.isbefore && Trigger.isInsert){
        
        List<Country_barcodes__c> mcs = Country_barcodes__c.getall().values();

        Map<integer,String> countryWithPhone = New Map<integer,String>();
         
        for(integer i=0;i<mcs.size();i++){
            countryWithPhone.put(mcs[i].country_phone_code__c,mcs[i].Name);
        }
        
         
        for(integer i=0;i<trigger.new.size();i++){
            if(countryWithPhone.ContainsKey(Trigger.new[i].BillingCountry)){
                trigger.new[i].Phone = countryWithPhone.get(Trigger.new[i].BillingCountry);
            }else{
                trigger.new[i].BillingCountry.addError('COUNTRY CODE DOES NOT EXISTS');
            }
        }
    }
  
}

 
Krishna SambarajuKrishna Sambaraju
Check the data type of the field country_phone_code__c, it might be decimal and you are trying add this value as a key to the Map<Integer, String> where the key is an integer.