11

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));
6

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.

5

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));
}
5
  • 1
    SETUP_OBJECTS - wouldn't this be faster if this were declared as a Set - the contains() method has got to be faster on sets than lists
    – cropredy
    Oct 15 '19 at 18:27
  • Sure. Originally I posted my initial version for testing, where I used a list. Of course, we should use a Set there. I've updated the answer.
    – Gennadiy
    Oct 15 '19 at 18:57
  • A couple of corrections based on my testing: CollaborationGroup is a Setup object, and QueueSobject is not a setup object (though it makes little sense, I get a Mixed DML error every time). Mar 16 '20 at 16:00
  • Correction: I'm not sure about QueueSobject; I'm getting odd results. I'll post another comment later if I figure it out. Mar 16 '20 at 16:15
  • Missing Territory2
    – dzh
    Apr 10 '20 at 1: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.