Apex method to find out if SObject is a setup object

Regular SObjects and Setup Objects can’t be mixed in DML otherwise you’ll experience a Mixed Dml Exception.

How can Apex code find out if a given SObjectType is such a setup object?

System.assert(isSetupObject(User.SObjectType);
System.assert( !isSetupObject(Contact.SObjectType));

Answer

As of Spring ’19 (and all prior versions), there is no method for describing if an object is a Setup object or not for the purpose of the governor limit, not in Apex, nor in the REST, SOAP, and Metadata APIs. Future visitors: if this changes, please feel free to comment/edit this answer.

Attribution
Source : Link , Question Author : Robert Sösemann , Answer Author : sfdcfox

Leave a Comment