Find the encrypted fields from inside an LWC

describefieldresultgetobjectinfolightning-web-componentsplatform-encryptionshield-encryption

I have Shield Platform Encryption turned on for Account.Name and a server-side field describe call:

System.debug(JSON.serializePretty(Account.Name.getDescribe()));

returns as expected these properties amongst many others:

aggregatable: false
encrypted: true
filterable: false
groupable: false
label: "Account Name"

But my LWC code that is doing this:

import ACCOUNT_OBJECT from '@salesforce/schema/Account';
import ACCOUNT_OBJECT_NAME from '@salesforce/schema/Account.Name';

@wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
wiredOpportunityObjectInfo({ error, data }) {
    if (data) {
        console.log(data.fields[ACCOUNT_OBJECT_NAME.fieldApiName]);
    } else if (error) {
        console.log(error);
    }
}

displays data (below) that shows no evidence of the encryption being turned on which is pretty disappointing. I'm trying to turn off lightning-datatable column sorts when such sorts are not possible in the database.

I see no mention of Shield Platform Encryption in the User Interface API Developer Guide.

Am I stuck with writing a dedicated Apex API to return the list of encrypted fields that I need?

apiName: "Name"
calculated: false
compound: true
compoundComponentName: null
compoundFieldName: "Name"
controllerName: null
controllingFields: [] (0)
createable: true
custom: false
dataType: "String"
extraTypeInfo: "SwitchablePersonName"
filterable: true
filteredLookupInfo: null
highScaleNumber: false
htmlFormatted: false
inlineHelpText: null
label: "Account Name"
length: 255
nameField: true
polymorphicForeignKey: false
precision: 0
reference: false
referenceTargetField: null
referenceToInfos: [] (0)
relationshipName: null
required: true
scale: 0
searchPrefilterable: false
sortable: true
unique: false
updateable: true

Best Answer

Did some more Googling and didn't find anything documented or a standard platform alternative. Happy to accept an alternative answer, but for now I've added this code:

/**
 * Return a set (a list has to be used for @AuraEnabled to allow the signature)
 * of encrypted fields for each requested type as getObjectInfo doesn't appear
 * to return that information.
 */
@AuraEnabled(cacheable=true)
public static Map<String, List<String>> findEncryptedFields(String[] types) {

    Map<String, List<String>> results = new Map<String, List<String>>();

    for (String tt: types) {

        // Avoid the cost of a global describe
        SObjectType t = ((SObject) Type.forName(tt).newInstance()).getSObjectType();

        List<String> fields = new List<String>();
        results.put(String.valueOf(t), fields);

        for (SObjectField f : t.getDescribe().fields.getMap().values()) {
            if (f.getDescribe().isEncrypted()) {
                fields.add(String.valueOf(f));
            }
        }
    }

    return results;
}

and at the client-side the column sorting is modified using that:

// Can't sort in the database if encrypted; getObjectInfo doesn't supply
// the necessary info so use a custom API
@wire(findEncryptedFields, { types: ['Account', 'Opportunity'] })
wiredFindEncryptedFields({ error, data }) {
    if (data) {
        if (data.Account.some(f => f === 'Name')) {
            this.columns.find(c => c.fieldName === 'accountUrl').sortable = false;
        }
        if (data.Opportunity.some(f => f === 'Name')) {
            this.columns.find(c => c.fieldName === 'opportunityUrl').sortable = false;
        }
    } else if (error) {
        this.showErrorToast(error);
    }
}