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.

  • 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 Oct 23 '18 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. – Ashish Sharma Oct 23 '18 at 7:53
  • But what is the issue with isQueryable in your case? – sanket kumar Oct 23 '18 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. – Ashish Sharma Oct 23 '18 at 8:00
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.

  • Thanks @sanket. It worked. I wasn't checking the list size returned after filtering. – Ashish Sharma Oct 25 '18 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.