Universal Containers stores user preferences in a Hierarchy Custom Setting, User_Prefs_c, with a Checkbox field, Show_Help_c. Company-level defaults are stored at the organizational level, but may be overridden at the user level. If a user has not overridden preferences, then the defaults should be used. How should the Show_Help_c preference be retrieved for the current user?
Select an option, then click Submit answer.
Reference / correct answer:
Boolean show = User_Prefs__c.getInstance().Show_Help__c;
Most accepted answer: B. Boolean show = User_Prefs__c.getInstance().Show_Help__c;
Community votes: A=1, B=2
B is correct. You will get null pointer in A if there is not User assigned record. As per description, org defaults are overridden by User assigned settings (there is Profile assignments but they are not mentioned in requirements). Ugly question upvoted 7 times
Selected Answer: B B is correct. upvoted 1 times
Selected Answer: B "If a user has not overridden preferences, then the defaults should be used." - this makes A infeasible upvoted 2 times
Selected Answer: A A is correct. I've tested it and it's working well. upvoted 1 times
The correct answer is B. It is mentioned in question that 'If a user has not overridden preferences, then the defaults should be used'. this can only possible if you use getInstance() method because it if it doesn't found value at user level it retrieves values from Org level. On the other hand, getValues(userId) returns null if no values present for that user. upvoted 4 times