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
raSFUserraSFUser 

conditional apex

I have some apex i want to run but only if Quotes are an enabled feature, i have tried to check this by doing the following.

public static Boolean sfQuotesEnabled () {
        boolean enabled;
        // sObject types to describe
        String[] types = new String[]{'Quote'};
            Schema.DescribeSobjectResult[] results;
            try{
                // Make the describe call
        		results = Schema.describeSObjects(types);
            }catch(DmlException e){
        		System.debug('sfQuotesEnabled: failed to get object type');
                enabled = false;
            }
        System.debug('Got describe information for ' + results.size() + ' sObjects.');
        
        if(results.size() > 0){
            enabled = true;          
        }
        return  enabled;
    }

Unfortunatly this is resulting in an "Entity is not org-accessible" error when i disable Quotes and the Apex falls over (does not continue to the catch) can somone help identify what my issue is / how i can do this check.
Footprints on the MoonFootprints on the Moon
Hey,
"Entity is not org-accessible" error will be there whenever you have object disabled (In your case, Quote). reason being Apex runtime will not be able to understand 'Quote' passed to Schema.describeSObjects as it is currently disabled.
Better to keep it enabled and then you can check for positive result onyl.

If you need further reading about this issue, refer - https://www.srinivas4sfdc.com/2016/01/error-entity-is-not-org-accessible.html

Let me know if this helps!