+ Start a Discussion

How do I edit a field in an sObject in a List when I know the objects ID?

I found a great bit of code in the Code Exchange


//Fetching all account in map
Map<id,account> aMap = new Map<id,account>([Select Id,Name from Account limit 50000]);

//Creating list of accounts
List<account> accList = aMap.values() ;

//Creating set of ids
Set<id> accIds = aMap.keySet() ;

If I knew that I wanted to change the Account with a particular ID's Email field to 'someone@someemail.com' is there a way to do so without looping through the results or worse executing a SOQL query for that specific record.?

You can call aMap.get(someAccountId) to get the specific account you're looking for. That is the purpose of a map.