You need to sign in to do that
Don't have an account?

How to update map values based on key?
I have a map with id and Account map<id, account> here the sample code
map<id, Account> updateAccts = new map<id, Account>(); List<Account> getAccts = [SELECT id, Case_Mailed_to_Group__c, Case_In_Work__c, CKE__C FROM Account WHERE ID in: caseAccUpdateIds ]; for(Account a: getAccts){ if(updateAccts.containskey(a.id){ //update account field in the map HOW update CKE__c field on account Account ac = updateAccts.get(a.Id); ac.CKE__C = a.CKE__C; //not working }eles{ updateAccts.put(a.id, a); } } update updateAccts.values();
Base on Salesforce account ID you are checking "containskey". In this case your code will not come in if condition. Because account ID will be unique because you are fatching "getAccts" list base on account id. So it will give unique acccont id only.
You can try below code.
Please let me know if this will help you.
Thanks
Amit Chaudhary
Your query is only going to return a single Account once, so looping through the query results and checking to see if you've already worked modified isn't going to do anything. The FOR loop will iterate through each Account in the collection once, so the check to see if updateAccts contains the Account will never be true; you'll need a 2nd loop (if that's appropriate).Within your loop, it looks like you're trying to set a CKE__c field to the value of a matching Account's CKE__c field, (even if the loop worked like you have it, the source and target values of the field would be the same).
I have to do second level of process, where I need to check if in previous logic the accont is added to the map and only update relevant field.
CKE__C is just an example, I am process 4 other fields
I have added comments, I am still working on my code. I am open for any suggestions to improve my code.
(1) I am creating map that require rate updates
(2) compare date fields to update only those account that were updated in the step #1