I have a map Map<Id, list<Boolean>> mapOfIdAndListBoolean = new Map<Id, list<Boolean>>(); I think I can get the whole list by using mapOfIdAndListBoolean .get(order.AccountId). Would I get the first element of the list by using mapOfIdAndListBoolean .get(order.AccountId)[0]?


Yes you will get the first element of the List.

Try below code for understanding in anonymous window.

Map<String, list<Boolean>> mapOfIdAndListBoolean = new Map<String, list<Boolean>>();

mapOfIdAndListBoolean.put('testStr',new List<Boolean>{true,false,true});
Boolean value = mapOfIdAndListBoolean.get('testStr')[0];
  • But You need to be very sure that you will not get "null" for the "key" here. Otherwise, you run into Null Pointer Exception – Rahul Gawale Oct 25 '19 at 7:16

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.