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
carramrodcarramrod 

Collection is Read-Only

    This is fired by an after insert/update/delete trigger on Account: getting collection is read-only error on the line updateMap.remove(a.ID);

Code:
 public static void runChildObjectUpdates(Account[] accs,Map<Id,Account> mNewAccountsMap){
Long datediff;
Map<Id,Account> updateMap = new Map<Id,Account>();
updateMap = mNewAccountsMap;
for(Account a:accs){
datediff = System.now().getTime() - a.Sent_To_Japan_Time__c.getTime();
//run update if the difference is <= 1 minute, 60000 milliseconds
if((a.Sent_To_Japan__c == true && datediff <= 60000) == false){
updateMap.remove(a.ID);
}
}//end for
if(mNewAccountsMap.size() > 0){
cFireChildUpdatesFromParent.fireUpdatesOnChildObjects(updateMap);
}
}

 



Message Edited by carramrod on 11-12-2008 02:27 PM
JonPJonP
What are you trying to do with these lines:

Code:
Map<Id,Account> updateMap = new Map<Id,Account>();
updateMap = mNewAccountsMap;

All the second line of this snippet does is make the variable updateMap reference the same map as the parameter mNewAccountsMap, throwing away the Map created in the first line.  If you are trying to copy the contents of mNewAccountsMap into a second Map, this is not how to do it.

Instead, you want to do this:
Code:
Map<Id,Account> updateMap = new Map<Id,Account>();
updateMap.putAll(mNewAccountsMap);

Now updateMap will contain all the same items as mNewAccountMap, but you can add or remove items from updateMap without affecting what items are in mNewAccountMap.

Note that Map.putAll() does not do a deep copy, meaning if Account A is in mNewAccountMap and you also put Account A in updateMap, you still only have one Account A in memory that is referenced by both Maps.

Jon