0

I have a map acctMap<id, decimal>. The keys are accountIds and value is a custom field. How to assign map keys to account ids and set the custom field to be the map values, so that I can update accounts using map data?

1

Just loop over the keyset of the map, and use the SObject constructor to set the Id and your custom field.

You need to loop over the keyset, because you can use the keys of the map to get the associated value, but not the other way around.

0

Assuming your map is called valuesByAcctId:

Account[] accts = new List<Account>();
for (Id acctId : valuesByAcctId.keySet() {
  accts.add(new(Account (Id = acctId, MyDecimalField__c = valuesByAcctId.get(acctId)));
}

update accts;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.