Explain an error in code below:
List<User> userList = [select id from User limit 1];
Set<User> usrs = new Set<User>();
usrs.add(userList[0]);
Map<Id, User> usrMap = new Map<Id, User>(usrs);
Set<Id> usrIds = usrMap.keySet();
It just gives me
An internal error occurred during: "Execute-Anonymous". java.lang.NullPointerException
I worked with real code which has a lot of maps of sets (Map<Id, Map<Id, User>>)
, I'm passing them around my methods. I encountered this Set problem in Batch class. I thought it was old Batch file problem when you can't create it normally or edit. But it seems it's a Set problem.
Hm... It seems it's a Map problem. I'm passing Set of users, but Map class doesn't have constructor with Set parameter. However, SFDC doesn't tell me anything about this. It just fires an internal error.
Why doesn't Salesforce tell me anything normal about Map constructor?
Map<ID,User> usrMap = New Map<ID,User>([Select Id from User Limit 1]);
Set<Id> usrIds = usrMap.keySet();
Try updating to that and see if it resolves the issue