0
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?

2
  • 1
    If this isn't with the API name, what will it be? An instance of an object? Mar 21, 2017 at 14:13
  • Without more detail about your use case it seems to me we should close this post as unclear what you are asking.
    – Adrian Larson
    Mar 21, 2017 at 20:05

2 Answers 2

6

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

0

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;
}
5
  • no need to loop -- Schema.getGlobalDescribe().get(label).getDescribe(),isAccessible() will do the trick - JH
    – Jochen
    Mar 21, 2017 at 18:16
  • @Jochen it's a map by API Name, not label...label isn't even unique.
    – Adrian Larson
    Mar 21, 2017 at 18:24
  • true. Not sure why you are assuming being passed the label. I was assuming being passed the API name, since the original post used a __c seems like API would be used. But, with your header, you are quite correct.
    – Jochen
    Mar 24, 2017 at 17:30
  • @Jochen The question is obviously quite unclear, but the OP asks can I check the FLS of Sobject without API name? and label seems like the only other potentially available data point.
    – Adrian Larson
    Mar 24, 2017 at 17:34
  • 1
    true -- I was reading the question (with the "dynamically") to mean without using the SObject name (or maybe Fieldname since the question is about FLS?) explicitly in the code. But the more I read the question, the less clear it is to me what Anu is looking for.
    – Jochen
    Mar 26, 2017 at 3:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .