I am trying to run very simple code in a static method under classs. Method:

public class TestUtil {
    public static void testMethod1() {
        for(String str : Schema.getGlobalDescribe().keyset()) {
            system.debug('++++' + str);

But this is only showing standard objects: Account , Contact , Product2 , Order , Opportunity and Pricebook2. All custom objects are coming correctly. But as know I do it from execute anyonymous it shows all objects as it does api callout to system. So not sure which permission is missing.

Update 1:

public static void testMethod2(){

        Schema.DescribeSObjectResult oppDescribe = Case.sObjectType.getDescribe();
        Map<String, Schema.SObjectField> fields = oppDescribe.fields.getMap();
        for (Schema.SObjectFIeld field: fields.values())

No standard field is showing here too. This class is not part of package so not sure whats going wrong here `

  • Does running the loop from the execute anonymous provide the same result? Commented Feb 18, 2020 at 12:56
  • No. It shows all the objects. Package is being created from the dev org so I think some package permission is causing this. Not sure which permission. Commented Feb 18, 2020 at 12:59
  • Check object visibility just to be sure, then try to execute your code in a without sharing class Commented Feb 18, 2020 at 13:20
  • with sharing does not enforce FLS, @J.Dillinger.
    – David Reed
    Commented Feb 18, 2020 at 13:21
  • Are you running the class and your Execute Anonymous while logged in as the same user?
    – David Reed
    Commented Feb 18, 2020 at 13:32


You must log in to answer this question.

Browse other questions tagged .