How to check permission on custom setting from apex code

1k views Asked by At

In Apex, given a custom setting "ThisSetting" containing items "ThisSettingFirst", "ThisSettingSecond", "ThisSettingThird", how would I correctly code these if statements?

if (the-currently-logged-on-user-doesnt-have-permission-to-read-custom-settings)

if (the-currently-logged-on-user-doesnt-have-permission-to-update-custom-settings)

if (the-currently-logged-on-user-doesnt-have-permission-to-read-custom-setting-ThisSetting)

if (the-currently-logged-on-user-doesnt-have-permission-to-update-custom-setting-ThisSetting)

if (the-currently-logged-on-user-doesnt-have-permission-to-read-custom-setting-ThisSettingFirst)

if (the-currently-logged-on-user-doesnt-have-permission-to-update-custom-setting-ThisSettingFirst)

Thanks.

1

There are 1 answers

2
Reshma On BEST ANSWER

You can use DescribeSObjectResult Class methods to check permissions of current user for that particular object/setting.

Schema.sObjectType objType = Schema.getGlobalDescribe().get('ThisSetting__c');
Schema.DescribeSObjectResult objDesc = objType.getDescribe();

if(objDesc.isUpdateable()) {
    System.debug('Updateable');
}
if(objDesc.isCreateable()) {
    System.debug('Createable');
}