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
Sreenu Reddy 16Sreenu Reddy 16 

Method does not exist or incorrect signature: void put(Decimal, String) from the type Map<Id,String> at line 8 column 24

sfdc flocks can you give me  help on below code .

Method does not exist or incorrect signature: void put(Decimal, String) from the type Map<Id,String> at line 8 column 24

trigger changeowner on Lead (before insert) {
     Map<Id,String> zipCodeUserMap = new Map<Id,String>();
     List<Zip_Code__c> zipCodes = new List<Zip_Code__c>();
     zipCodes = [Select id,ZipCode__c,Counserlor__c  from Zip_Code__c];
      
      for (Zip_Code__c zc :zipCodes){
        
        zipCodeUserMap.put(zc.ZipCode__c,zc.Counserlor__c);   
     }
       
       
       
       for(Lead l : Trigger.new) 
       {
        if(zipCodeUserMap.containsKey(l.Zip_Code__c)) 
        {
            l.Ownerid = zipCodeUserMap.get(l.Zip_Code__c);
        }
       }
}
Best Answer chosen by Sreenu Reddy 16
Ajay K DubediAjay K Dubedi
Hi Sreenu,
Try this trigger:

trigger changeowner on Lead (before insert) {
    Map<String, Id> zipCodeUserMap = new Map<String, Id>();
    List<Zip_Code__c> zipCodes = new List<Zip_Code__c>();
    zipCodes = [Select id, ZipCode__c, Counserlor__c  from Zip_Code__c WHERE ZipCode__c != null AND Counserlor__c != null];
    if(zipCodes.size() > 0) {
        for (Zip_Code__c zc : zipCodes) {
            zipCodeUserMap.put(String.ValueOf(zc.ZipCode__c), Id.ValueOf(zc.Counserlor__c));   
        }
        for(Lead l : Trigger.new) 
        {
            if(zipCodeUserMap.containsKey(l.Zip_Code__c)) 
            {
                l.Ownerid = zipCodeUserMap.get(l.Zip_Code__c);
            }
        }
    }  
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi

All Answers

Ajay K DubediAjay K Dubedi
Hi Sreenu,
Try this trigger:

trigger changeowner on Lead (before insert) {
    Map<String, Id> zipCodeUserMap = new Map<String, Id>();
    List<Zip_Code__c> zipCodes = new List<Zip_Code__c>();
    zipCodes = [Select id, ZipCode__c, Counserlor__c  from Zip_Code__c WHERE ZipCode__c != null AND Counserlor__c != null];
    if(zipCodes.size() > 0) {
        for (Zip_Code__c zc : zipCodes) {
            zipCodeUserMap.put(String.ValueOf(zc.ZipCode__c), Id.ValueOf(zc.Counserlor__c));   
        }
        for(Lead l : Trigger.new) 
        {
            if(zipCodeUserMap.containsKey(l.Zip_Code__c)) 
            {
                l.Ownerid = zipCodeUserMap.get(l.Zip_Code__c);
            }
        }
    }  
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
This was selected as the best answer
Deepali KulshresthaDeepali Kulshrestha
Hi Sreenu,

You create a map 'Map<Id, String>' but you put (Decimal, String) into this map that's why it throws an error.
I make some changes in your code. So try the following code it may be helpful for you:
       
trigger changeowner on Lead (before insert) {
     Map<Decimal,String> zipCodeUserMap = new Map<Decimal,String>();
     List<Zip_Code__c> zipCodes = new List<Zip_Code__c>();
     zipCodes = [Select id,ZipCode__c,Counserlor__c  from Zip_Code__c LIMIT 10000];
      for (Zip_Code__c zc :zipCodes){
        zipCodeUserMap.put(zc.ZipCode__c,zc.Counserlor__c);   
     }
       for(Lead l : Trigger.new) 
       {
        if(zipCodeUserMap.containsKey(l.Zip_Code__c)) 
        {
            l.Ownerid = zipCodeUserMap.get(l.Zip_Code__c);
        }
       }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
Sreenu Reddy 16Sreenu Reddy 16
I getting Variable does not exist: Zip_Code__c.  I have  tryed Variable  " ZipCode__c" also .
Sreenu Reddy 16Sreenu Reddy 16
 Hi  Deepali & Ajay ,
I getting Variable does not exist: Zip_Code__c.  I have  tryed Variable  " ZipCode__c" also . can you give best solution why it is getting like this error .
Thanks,
Srini..
Sreenu Reddy 16Sreenu Reddy 16
i am ok this  I got solution. Thanks you support/advise .