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
swain 10swain 10 

how to put list<sobject> collection field in map key value pair .........Showing Error

List<sObject> allResult= OV_Searchcc360.isDuplicate(objectType, fields, sources, null);

So allResult is a List of array having multiple records of one object , each record having several fields. I need to use 2 fields from this collection in a key value pair ie:- Id and Score field present inside the array. so i written this below code to iterate.

List<Map<String,String>> allResultMap = new List<Map<String,String>>(); 
              
        for(sObject objSObject : allResult)
        Map<String,String> finalResultMap = new Map<String,String>();   
         {
          allResultMap.put(objSObject.DSE__DS_Account__c, objSObject.DSE__DS_Score__c);
          system.debug('-------allResultMap-----'+allResultMap);    
          }
     
But it is showing that value doesnt exist :DSE__DS_Account__c and  DSE__DS_Score__c. But both fields present in the array. Please help.

And after this I need to sort according to score points.        
Best Answer chosen by swain 10
Japleen KaurJapleen Kaur
Here, I have assumed the field Score__c of String type. You can change it according to your requirements.
 
Map<ID, String> newMap = new Map<ID, String>();                            //created a new map
    for(sObject s : allResult)                                             
    {
        newMap.put(s.id, s.score__c); 
    }