if(Schema.Accountr__c.getSObjectType().getDescribe().isAccessible())
In the Above line, I am checking whether that Accountr__c
object data is accessible or not. My query is, can I check the FLS of Sobject
without API name?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityif(Schema.Accountr__c.getSObjectType().getDescribe().isAccessible())
In the Above line, I am checking whether that Accountr__c
object data is accessible or not. My query is, can I check the FLS of Sobject
without API name?
You could do something like:
((sObject)Type.forName('Account').newInstance()).getSObjectType().getDescribe().isAccessible();
Or you could do a global describe and get the values from the returned map
Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
But you at least need to have the String of the Object name. If you don't at least have that they you are essentially asking if we can check isAccessbile()
on unknown
which is not possible
The only reasonable interpretation I can make of your ask here is that you might want to check accessibility based on the label of an object? It's the only other data point you have besides the name. You can do it, you just have to loop through the global describe until you find a match. It's certainly less efficient.
public static Boolean isObjectLabelAccessible(String label)
{
Boolean isAccessible = false;
for (SObjectType sObjectType : Schema.getGlobalDescribe().values())
{
if (sObjectType.getDescribe().getLabel() == label)
{
isAccessible = sObjectType.getDescribe().isAccessible();
break;
}
}
return isAccessible;
}