+ Start a Discussion
Sumesh ChandranSumesh Chandran 

Map put method not working


 

I am trying to put the id from database.saveresult return values and then the matching value from the citylist list into this map below, but I get an error "Method does not exist or incorrect signature: void put(sumchans__City_Master__c, Id) from the type Map<String,String>"
 
Database.SaveResult[] saveCityMaster = Database.Insert(cityList, false);
        Map<String,String> findCityId = new Map<String,String>();
        for (Database.SaveResult sr : saveCityMaster) {
            if (!sr.isSuccess()) {
                findCityId.put(cityList.get(0),sr.getId());
            }
        }

 
Best Answer chosen by Sumesh Chandran
Christan G 4Christan G 4
I have a few questions: Are you trying to retrieve the record from the list and input it into your map? What is the datatype for cityList? I assume it's datatype is sumchans__City_Master__c. I have written code below to resolve your issue. 
Database.SaveResult[] saveCityMaster = Database.Insert(cityList, false);

         Map<Id, sumschan_City_Master__c> cityListMap = new Map<Id, sumschan_City_Master__c>(cityList);

        Map<Id, sumschan_City_Master__c> findCityId = new Map<Id, sumschan_City_Master__c>();

        for (Database.SaveResult sr : saveCityMaster) {
            if (sr.isSuccess()) {

               findCityId.put(sr.getId() , cityListMap.get(sr.getId());

            }
        }
If sumchans__City_Master__c isn't the datatype for cityList, please replace it with the correct datatype in the code. I haven't had a chance to test the code but I have reviewed it thoroughly and don't think, it'll cause an error. 

I hope it helps!
 

All Answers

Naga  AlapatiNaga Alapati
Hi Sumesh,

You need to use Map<String, Id> because you are trying to place Id as the value in the map. Try this one
 
Database.SaveResult[] saveCityMaster = Database.Insert(cityList, false);
        Map<String,Id> findCityId = new Map<String,Id>();
        for (Database.SaveResult sr : saveCityMaster) {
            if (sr.isSuccess()) {
                findCityId.put(cityList.get(0),sr.getId());
            }
        }


Regards,
Naga
Sumesh ChandranSumesh Chandran
Hello Naga, tried the code above, It still gives me the same error.
manish arora 25manish arora 25
manish arora 25manish arora 25
Pyar Tenu Karde Gabru (https://getsongname.com/pyar-tenu-karde-gabru-mp3-song/) this song by Ravneet Singh , song is been written Ravneet Singh and composed by Sumneet Download Tum Hi Aana Song mp3 songs i 128Kbps, 192Kbps and 320Kbps – in HD High Quality Audio.
manish arora 25manish arora 25
Presenting Latest New Bollywood Song Lyrics of Fauj Ki Dahaad Song Lyrics Mr. BratBea From Kartikeye Ojha & Pranshu Jha . The latest Upcomin Movie Code M Song Fauj Ki Dahaad (https://getlyricsname.com/fauj-ki-dahaad-song-lyrics-code-m-mr-bratbeat/) Lyrics are written by Kumaar Mr. BratBeat and Music Directed by Kartikeye Ojha & Pranshu Jha
Christan G 4Christan G 4
I have a few questions: Are you trying to retrieve the record from the list and input it into your map? What is the datatype for cityList? I assume it's datatype is sumchans__City_Master__c. I have written code below to resolve your issue. 
Database.SaveResult[] saveCityMaster = Database.Insert(cityList, false);

         Map<Id, sumschan_City_Master__c> cityListMap = new Map<Id, sumschan_City_Master__c>(cityList);

        Map<Id, sumschan_City_Master__c> findCityId = new Map<Id, sumschan_City_Master__c>();

        for (Database.SaveResult sr : saveCityMaster) {
            if (sr.isSuccess()) {

               findCityId.put(sr.getId() , cityListMap.get(sr.getId());

            }
        }
If sumchans__City_Master__c isn't the datatype for cityList, please replace it with the correct datatype in the code. I haven't had a chance to test the code but I have reviewed it thoroughly and don't think, it'll cause an error. 

I hope it helps!
 
This was selected as the best answer
Sumesh ChandranSumesh Chandran
Thanks Christian, That worked!
bittu biswasbittu biswas
Laal Genda Phool (https://webmusicmp3.in/filelist/51/laal-genda-phool-ringtone-badshah-ft-payal-dev/new2old/1.html) Presenting the audio song ” Laal Genda Phool ” this song by Badshah & Payal Dev , song is been written Badshah
manish arora 26manish arora 26
Genda Phool A Lyrics & Song Details: Presenting Latest New Song Lyrics Genda Phool  Song Badshah (https://songname.co/genda-phool-song-lyrics-in-hindi-and-english-badshah/), Payal Dev. The latest Song is sung by features Jacqueline Fernandez.