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
Ram Shiva KumarRam Shiva Kumar 

Custom Settings Methods


Can  any body tell me the difference betwen the getvalues() and getinstance () methods  customsettings.

Anil kumar GorantalaAnil kumar Gorantala
getInstance() and getValues() do not always return the same object for hierarchical custom settings (although they do for list custom settings).
getInstance() gets you the merged values for all hierarchy levels above and including its argument (so if the user with id myUserId has a null value for a field, getInstance(myUserId) can inherit a value from the user's profile or the org-wide defaults)
getValues() gets you the record as specified for its argument (so if the user with id myUserId has a null value for a field, getValues(userId) will always have a null value for the field)
Anil kumar is right. They are different for hierarchy.

Sunny Gill 5Sunny Gill 5
Hi ram ram 11,

getValues() and getInstance() method will return identical values for list type custom setting.

But for the heirarchy type custom setting. getValues('XYZ') will return if any record is present for that user trying to access the value but getInstance('XYZ') will traverse up the heirarchy order and will return like if no record is present for the user trying to access the record but a Org wide default value is present then it will return OWD value but in this case getValue() will return null.