I'm writing code that uses the somewhat new "Security Classification" on custom fields to modify its behavior. This value is not (yet?) available via DescribeFieldResult, so I'm querying the Tooling API object FieldDefinition. This was working fine, until my unit tests reached the point where I needed to interact with two objects, and so I needed to run two Tooling API queries (the work is invoked via trigger; it does not make sense to combine these into a single query). After a lot of debugging and head-scratching, I arrived at the conclusion that the first such Tooling API query within an Apex transaction returns the SecurityClassification field, but the second does not.

I've narrowed it down to the following Anonymous Apex reproduction case. Note that I'm working with FSC objects, and that both objects have at least 1 field with a SecurityClassification value set. If I run the embedded queries in Developer Console, BOTH queries return values for the SecurityClassification field for at least one result record.

List<FieldDefinition> AcctFields = [
  SELECT DeveloperName, SecurityClassification, EntityDefinition.QualifiedApiName
    FROM FieldDefinition
   WHERE EntityDefinition.QualifiedApiName='FinServ__FinancialAccount__c'
String AcctFieldsJSON = JSON.serialize(AcctFields);
System.assert(AcctFieldsJSON.contains('SecurityClassification')); //confirm it appears at least once

List<FieldDefinition> TransFields = [
  SELECT DeveloperName, SecurityClassification, EntityDefinition.QualifiedApiName
    FROM FieldDefinition
   WHERE EntityDefinition.QualifiedApiName='FinServ__FinancialAccountTransaction__c'
String TransFieldsJSON = JSON.serialize(TransFields);
System.assert(TransFieldsJSON.contains('SecurityClassification')); //confirm it appears at least once

When the above code it run, the first assertion passes (the query results of FinServ__FinancialAccount__c fields contain SecurityClassification), and the second assertion fails (the query results of FinServ__FinancialAccountTransaction__c fields do not). However, if I simply move the first block of code to the bottom, the results change. The new first assertion (FinServ__FinancialAccountTransaction__c) passes, and the second assertion (FinServ__FinancialAccount__c) does not.

This is not related to the use of FSC or Managed Package objects/fields in general; I set the Security Classification on a couple custom fields on Account and Contact and repeated the test with those objects. The first query to run always returns the SecurityClassification values, and the second query to run never does.

I'm assuming this must be a bug? Is there any known workaround? Is there a better way to check the SecurityClassification of a custom field from Apex?

1 Answer 1


Salesforce support eventually confirmed that this is a bug caused by internal caching, and suggested as a workaround including all potentially needed SObjects in the first query. Further details are posted in Known Issue W-7605641

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .