You need to sign in to do that
Don't have an account?
steve nabors 7
Which is better in an iteration over a Map, get methods or an object instance?
Which is better in an iteration over a Map, get methods, or an object instance?
Example:
Map<Id, SObject> mapName = new Map<Id, SObject>([ SOQL Query ]);
for (Id key : mapName.keySet()){
EITHER THIS:
var1 = mapName.get(key).field1
var2 = mapName.get(key).field2
var3 = mapName.get(key).field3
.......
OR THIS:
SObject o = mapName.get(key);
var1 = o.field1
var2 = o.field2
var3 = o.field3
.......
Example:
Map<Id, SObject> mapName = new Map<Id, SObject>([ SOQL Query ]);
for (Id key : mapName.keySet()){
EITHER THIS:
var1 = mapName.get(key).field1
var2 = mapName.get(key).field2
var3 = mapName.get(key).field3
.......
OR THIS:
SObject o = mapName.get(key);
var1 = o.field1
var2 = o.field2
var3 = o.field3
.......
Also you can see on the documentation that salesforce uses the get method to retrieve the data but does not compare this exact situation.
Here you have other considerations for map:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_maps.htm
If it helps please mark as correct, it may help others.
You can try this ,
https://developer.salesforce.com/forums/?id=906F00000008xHJIAY
It might help you.
Thanks.