Apex method to find out if SObject is a setup object

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.


There is still no in-built method in APEX. So, I had to write my own method for this. Maybe, the list is not full, but it's enough for 99% cases. I hope it will be useful for someone.

private static Set<String> SETUP_OBJECTS = new Set<String> { 'ActionLinkGroupTemplate',
    'ActionLinkTemplate', 'AdminSetupEvent', 'AdminSetupEventStream', 'AggregateResult',
    'AnimationRule', 'ApexClass', 'ApexClassMember', 'ApexCodeCoverage',
    'ApexCodeCoverageAggregate', 'ApexComponent', 'ApexComponentMember',
    'ApexEmailNotification', 'ApexExecutionOverlayAction', 'ApexExecutionOverlayResult',
    'ApexLog', 'ApexOrgWideCoverage', 'ApexPage', 'ApexPageInfo', 'ApexPageMember',
    'ApexResult', 'ApexTestQueueItem', 'ApexTestResult', 'ApexTestResultLimits',
    'ApexTestRunResult', 'ApexTestSuite', 'ApexTrigger', 'ApexTriggerMember', 'ApiEvent',
    'ApiEventStream', 'AppAnalyticsQueryRequest', 'AppDefinition', 'AppMenuItem',
    'AppTabMember', 'AssetTokenEvent', 'AssignmentRule', 'AsyncApexJob', 'AsyncOperationEvent',
    'AsyncOperationStatus', 'AuraDefinition', 'AuraDefinitionBundle',
    'AuraDefinitionBundleInfo', 'AuraDefinitionInfo', 'AuthConfig', 'AuthConfigProviders',
    'AuthProvider', 'AuthSession', 'AutoResponseRule', 'BackgroundOperation',
    'BatchApexErrorEvent', 'BrandingSet', 'BrandingSetProperty', 'BrandTemplate',
    'BusinessHours', 'BusinessProcess', 'CampaignMemberStatus', 'CaseStatus', 'Certificate',
    'CleanDataService', 'CleanRule', 'ClientBrowser', 'ColorDefinition', 'Community',
    'CommunityWorkspacesNode', 'CompactLayout', 'CompactLayoutInfo', 'CompactLayoutItemInfo',
    'ConnectedApplication', 'ContainerAsyncRequest', 'ContentBody', 'ContentHubItem',
    'ContentHubRepository', 'ContentWorkspace', 'ContractStatus', 'CorsWhitelistEntry',
    'CronJobDetail', 'CronTrigger', 'CspTrustedSite', 'CustomApplication', 'CustomBrand',
    'CustomBrandAsset', 'CustomField', 'CustomFieldMember', 'CustomHelpMenuItem',
    'CustomHelpMenuSection', 'CustomHttpHeader', 'CustomNotificationType', 'CustomObject',
    'CustomObjectUserLicenseMetrics', 'CustomPermission', 'CustomPermissionDependency',
    'CustomTab', 'Dashboard', 'DashboardComponent', 'DataAssessmentConfigItem',
    'DataAssessmentFieldMetric', 'DataAssessmentMetric', 'DataAssessmentValueMetric',
    'DatacloudAddress', 'DataIntegrationRecordPurchasePermission', 'DataStatistics',
    'DataType', 'DataUseLegalBasis', 'DataUsePurpose', 'DebugLevel', 'DeployDetails',
    'DirectMessage', 'DirectMessageMember', 'Document', 'DocumentAttachmentMap', 'Domain',
    'DomainSite', 'DuplicateJobDefinition', 'DuplicateJobMatchingRuleDefinition',
    'DuplicateRecordItem', 'DuplicateRecordSet', 'DuplicateRule', 'EmailCapture',
    'EmailDomainFilter', 'EmailDomainKey', 'EmailMessage', 'EmailRelay',
    'EmailServicesAddress', 'EmailServicesFunction', 'EmailStatus', 'EmailTemplate',
    'EmbeddedServiceBranding', 'EmbeddedServiceConfig', 'EmbeddedServiceCustomLabel',
    'EmbeddedServiceDetail', 'EmbeddedServiceFieldService', 'EmbeddedServiceLabel',
    'EmbeddedServiceLiveAgent', 'EmbeddedServiceQuickAction', 'EngagementEvent',
    'EnhancedLetterhead', 'EntityDefinition', 'EntityLimit', 'EntityParticle',
    'EventBusSubscriber', 'EventDelivery', 'EventLogFile', 'EventSubscription',
    'ExpressionFilter', 'ExpressionFilterCriteria', 'ExternalDataSource',
    'ExternalDataUserAuth', 'ExternalServiceRegistration', 'ExternalString', 'FieldDefinition',
    'FieldMapping', 'FieldMappingField', 'FieldMappingRow', 'FieldPermissions',
    'FieldSecurityClassification', 'FieldSet', 'FileSearchActivity', 'FiscalYearSettings',
    'FlexiPage', 'FlexQueueItem', 'Flow', 'FlowDefinition', 'FlowDefinitionView',
    'FlowElementTestCoverage', 'FlowInterview', 'FlowTestCoverage', 'FlowVariableView',
    'FlowVersionView', 'ForecastingDisplayedFamily', 'FormulaFunction', 'FormulaOperator',
    'GlobalValueSet', 'GrantedByLicense', 'Group', 'GroupMember',
    'HeapDump', 'HistoryRetentionJob', 'Holiday', 'HomePageComponent', 'HomePageLayout',
    'IconDefinition', 'IdpEventLog', 'IframeWhiteListUrl', 'Index', 'IndexField',
    'InstalledMobileApp', 'InstalledSubscriberPackage', 'InstalledSubscriberPackageVersion',
    'KeywordList', 'KnowledgeableUser', 'Layout', 'LeadStatus', 'LightningComponentBundle',
    'LightningComponentResource', 'LightningExitByPageMetrics', 'LightningExperienceTheme',
    'LightningToggleMetrics', 'LightningUriEvent', 'LightningUriEventStream',
    'LightningUsageByAppTypeMetrics', 'LightningUsageByBrowserMetrics',
    'LightningUsageByFlexiPageMetrics', 'LightningUsageByPageMetrics', 'ListView',
    'ListViewChart', 'ListViewChartInstance', 'ListViewEvent', 'ListViewEventStream',
    'LoginAsEvent', 'LoginAsEventStream', 'LoginEvent', 'LoginEventStream', 'LoginGeo',
    'LoginIp', 'LogoutEvent', 'LogoutEventStream', 'LookupFilter', 'Macro', 'MacroInstruction',
    'MacroUsage', 'MailmergeTemplate', 'ManagedContentNodeType', 'ManagedContentType',
    'MatchingRule', 'MatchingRuleItem', 'MenuItem', 'MetadataComponentDependency',
    'MetadataContainer', 'MetadataPackage', 'MetadataPackageVersion', 'Metric',
    'MetricDataLink', 'MobileApplicationDetail', 'ModerationRule', 'MyDomainDiscoverableLogin',
    'Name', 'NamedCredential', 'NavigationLinkSet', 'NavigationMenuItem', 'Network',
    'NetworkActivityAudit', 'NetworkAffinity', 'NetworkDiscoverableLogin', 'NetworkMember',
    'NetworkMemberGroup', 'NetworkModeration', 'NetworkPageOverride', 'NetworkSelfRegistration',
    'NetworkUserHistoryRecent', 'OauthCustomScope', 'OauthToken', 'ObjectPermissions',
    'OnboardingMetrics', 'OperationLog', 'OpportunitySplitType', 'OpportunityStage',
    'Organization', 'OrgDeleteRequest', 'OrgLifecycleNotification', 'OrgWideEmailAddress',
    'OutgoingEmail', 'OwnerChangeOptionInfo', 'Package2', 'Package2Member', 'Package2Version',
    'Package2VersionCreateRequest', 'Package2VersionCreateRequestError',
    'PackageInstallRequest', 'PackageLicense', 'PackageUploadRequest',
    'PackageVersionUninstallRequestError', 'PathAssistant', 'PathAssistantStepInfo',
    'PathAssistantStepItem', 'Period', 'PermissionDependency', 'PermissionSet',
    'PermissionSetAssignment', 'PermissionSetGroup', 'PermissionSetGroupComponent',
    'PermissionSetLicense', 'PermissionSetLicenseAssign', 'PermissionSetPortalDelegate',
    'PermissionSetTabSetting', 'PicklistValueInfo', 'PlatformAction', 'PlatformCachePartition',
    'PlatformCachePartitionType', 'PlatformEventChannel', 'PlatformEventChannelMember',
    'PlatformStatusAlertEvent', 'PostTemplate', 'ProcessDefinition', 'ProcessInstance',
    'ProcessInstanceNode', 'ProcessInstanceStep', 'ProcessInstanceWorkitem', 'ProcessNode',
    'ProductConsumptionSchedule', 'Profile', 'ProfileLayout', 'Prompt', 'PromptAction',
    'PromptVersion', 'Publisher', 'PushTopic', 'PushUpgradeExcludedOrg', 'QueryResult',
    'QueueSobject', 'QuickActionDefinition', 'QuickActionList', 'QuickActionListItem',
    'QuickText', 'QuickTextUsage', 'RecentlyViewed', 'Recommendation', 'RecommendationStrategy',
    'RecordAction', 'RecordActionDeployment', 'RecordType', 'RelationshipDomain',
    'RelationshipInfo', 'RemoteProxy', 'Report', 'ReportEvent', 'ReportEventStream',
    'ReputationLevel', 'ReputationPointsRule', 'S2XEventMap', 'SamlSsoConfig', 'SandboxInfo',
    'SandboxProcess', 'Scontrol', 'SearchActivity', 'SearchLayout', 'SearchPromotionRule',
    'SecureAgent', 'SecureAgentPlugin', 'SecureAgentPluginProperty', 'SecureAgentsCluster',
    'SecurityCustomBaseline', 'SecurityHealthCheck', 'SecurityHealthCheckRisks',
    'ServiceFieldDataType', 'SessionPermSetActivation', 'SetupAuditTrail', 'SetupEntityAccess',
    'Site', 'SiteDetail', 'SiteIframeWhiteListUrl', 'SOQLResult', 'SolutionStatus',
    'SourceMember', 'Stamp', 'StampAssignment', 'StandardAction', 'StandardValueSet',
    'StaticResource', 'StreamingChannel', 'SubscriberPackage', 'SubscriberPackageVersion',
    'SubscriberPackageVersionUninstallRequest', 'SymbolTable', 'TabDefinition', 'TaskPriority',
    'TaskStatus', 'TenantUsageEntitlement', 'TestSuiteMembership', 'ThirdPartyAccountLink',
    'TimeSheetTemplate', 'TraceFlag', 'TransactionSecurityPolicy', 'TwoFactorInfo',
    'TwoFactorMethodsInfo', 'TwoFactorTempCode', 'UriEvent', 'UriEventStream', 'User',
    'UserAppInfo', 'UserAppMenuCustomization', 'UserAppMenuItem', 'UserCriteria',
    'UserCustomBadge', 'UserEmailPreferredPerson', 'UserEntityAccess', 'UserFieldAccess',
    'UserLicense', 'UserListView', 'UserListViewCriterion', 'UserLogin', 'UserPackageLicense',
    'UserPermissionAccess', 'UserPreference', 'UserProvAccount', 'UserProvAccountStaging',
    'UserProvisioningConfig', 'UserProvisioningLog', 'UserProvisioningRequest',
    'UserProvMockTarget', 'UserRecordAccess', 'ValidationRule', 'VisualforceAccessMetrics',
    'WebLink', 'WorkflowAlert', 'WorkflowFieldUpdate', 'WorkflowOutboundMessage',
    'WorkflowRule', 'WorkflowTask', 'WorkSkillRouting', 'WorkSkillRoutingAttribute' };

public static Boolean isSetupSObject(SObjectType sObjectType)
{
    if (sObjectType == null) { return false; }

    return SETUP_OBJECTS.contains(String.valueOf(sObjectType));
}