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
morganeCRMCLOUDERmorganeCRMCLOUDER 

updating database with values from a map

Hello, 

 

I have a map like this :

 

Map<String, Double> myMap;

I filled it with a loop, it's works fine.  

 

Now how do I udpate the fields corresponding to this query : 

 

List<UBI__SnOP_Planning_Record__c> listQuery = [SELECT id, Quantity__c   FROM myTable ]

 

with the values from myMap ? 

Best Answer chosen by Admin (Salesforce Developers) 
morganeCRMCLOUDERmorganeCRMCLOUDER

It's ok :) 

 

I did this : 

 

for(Integer i = 0; i < listQuery.size(); i++){ 
  if(myMap.containsKey(listQuery[i].id))
    listQuery[i].Quantity__c = myMap.get(listIds[i]); 
} 
update listQuery;

 

All Answers

Avidev9Avidev9
Well can you explain a bit more ?
How you are planning to compare which record corresponds to which key\value in map
morganeCRMCLOUDERmorganeCRMCLOUDER

It's ok :) 

 

I did this : 

 

for(Integer i = 0; i < listQuery.size(); i++){ 
  if(myMap.containsKey(listQuery[i].id))
    listQuery[i].Quantity__c = myMap.get(listIds[i]); 
} 
update listQuery;

 

This was selected as the best answer