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
punit tyagi 7punit tyagi 7 

how to fetch acessible sobject in org not field??

please help how to fetch accessible sobject in org  how???
not mentioned or ask accessible field???
VinayVinay (Salesforce Developers) 
Hi Punit,

Check below link.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SObjects_accessing_fields.htm

You can also check whether a particular object or field is accessible to the logged in user or not.

Try below snippet.
 
Map<String, Schema.SObjectType> globalDescribe = Schema.getGlobalDescribe(); 
List<String> apiNames = new List<String>();

for(string objectApi: globalDescribe.keyset()){             
    apiNames.add(objectApi);
}

Schema.DescribeSobjectResult[] results  = Schema.describeSObjects(apiNames);
for(Schema.DescribeSobjectResult describeResult  : results){                
    if(describeResult.isAccessible()) {
        System.debug(describeResult.getLabel()+'~~~~~~~~~~~~~~is accessible to this user');
        for(Schema.SobjectField  field: describeResult.fields.getMap().values()){
            if(field.Describe().isAccessible()){
                console.log(field.Describe().getLabel()+'~~~~~~~~~~~~~~~~~~~~is accessible');  
            }
        }
    }
}

Hope this helps...

Thanks,
SwethaSwetha (Salesforce Developers) 
HI Punit,

You can check for the accessibility of an object like this:
{!$ObjectType.objectname.accessible}

For example, to check if you have access to the standard Lead object, use the following code:
{!$ObjectType.Lead.accessible}
This expression returns a true or false value.

Reference: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_std_checking_accessibility.htm

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you