0

I'm working on a SOQL query builder which should show all the Objects of an Org which are supported in SOQL query. I've used Schema.getGlobalDescribe() to get all objects name. Though it returns all the Objects in a map, it also includes all those objects that aren't supported in SOQL such as InsightsExternalDataPart. Schema.DescribeSObjectResult's isQueryable is also not working in this case. Any help or guidance is much appreciated. Don't have much code to post as it only has Schema describe calls.

4
  • isQueryable should be able to tell you whether object is queryable or not. Note that it returns true if object supports query at top level. InsightsExternalDataPart is queryable ...are u getting any issue?
    – Ayub
    Commented Oct 23, 2018 at 7:37
  • my issue is not specific to InsightsExternalDataPart. I just want to filter out objects that aren't supported in SOQL. There are plenty of them. For eg. WorkPerformanceCycleShare, MetricDataLink etc. I need to segregate such objects from the list so that list only contains the objects that are supported under SOQL. Hope this clears my question more. Commented Oct 23, 2018 at 7:53
  • But what is the issue with isQueryable in your case? Commented Oct 23, 2018 at 7:58
  • It isn't filtering objects. I've put this check in my code and list returned is no different when check is not there. Commented Oct 23, 2018 at 8:00

1 Answer 1

3

As per Salesforce Documentation, isQueryable() returns true if the object can be queried by the current user, false otherwise. Try this:-

Integer i=0;
Integer x=0;
for ( Schema.SObjectType o : Schema.getGlobalDescribe().values() )
{
    Schema.DescribeSObjectResult objResult = o.getDescribe();
    if(objResult.isQueryable()==true){
        i++;
        system.debug(objResult.getLabel());
    }
    else{
        x++;
        system.debug(objResult.getLabel());
        }
    //system.debug( 'Sobject: ' + objResult );
    //system.debug( 'Sobject API Name: ' + objResult.getName() );
    //system.debug( 'Sobject Label Name: ' + objResult.getLabel() );
}
system.debug('i-->>'+i);
system.debug('x-->>'+x);

As per your comment, isQueryable() is returning the same list. I am not sure how you are checking But try with above code. It is returning correct values.

1
  • Thanks @sanket. It worked. I wasn't checking the list size returned after filtering. Commented Oct 25, 2018 at 5:42

You must log in to answer this question.

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