Sub topic 16
Representing and Deploying FLS as Metadata
This chapter assumes you know how to set field access in Setup, what permission sets are, and basic Salesforce DX project structure. You will see how FLS is stored as metadata and how to deploy it safely.
Where FLS lives in metadata
FLS is not stored on the field. It is stored in the container that grants access: a permission set or a profile. Each grant is a fieldPermissions entry that names one field and two flags, readable and editable.
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Account Notes Access</label>
<fieldPermissions>
<editable>true</editable>
<field>Account.Internal_Notes__c</field>
<readable>true</readable>
</fieldPermissions>
</PermissionSet>The field name uses the form Object.FieldApiName. A field with no entry in any container the user holds is invisible to that user.
Deploying the field and its access together
A field deployed on its own is hidden from non-admin users until some permission set or profile grants access. Deploy the field and the permission set in the same package so access exists the moment the field does.
The package.xml below lists both.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Account.Internal_Notes__c</members>
<name>CustomField</name>
</types>
<types>
<members>Account_Notes_Access</members>
<name>PermissionSet</name>
</types>
<version>60.0</version>
</Package>Then deploy with the Salesforce CLI:
sf project deploy start --manifest manifest/package.xml --target-org my-sandboxProfiles versus permission sets in source
Profile files are large and list every object, field, and setting. Retrieving a profile returns only the parts related to the other components in your manifest, which makes profile diffs noisy and merges error-prone. Permission sets are small and focused. Put new field access in permission sets and keep profile changes to a minimum.
| Container | Source file size | Merge risk | Best use |
|---|---|---|---|
| Profile | Large | High | Baseline settings such as login hours |
| Permission set | Small | Low | Field and object access |
| Permission set group | Small | Low | Bundling permission sets by role |
Common errors
- Field required but not editable. Deployment fails if a permission set marks a required field as
readablefalse. Required fields and Universally Required fields cannot have FLS entries, so omit them. - Missing readable flag.
editabletrue withreadablefalse is invalid. Edit access implies read access. - Wrong deployment order in scripts. If you deploy permission sets separately, deploy the field first, or the grant fails because the field does not exist yet.
- Deploy succeeds but users see nothing. The permission set exists but was never assigned. Metadata deploys the grant, not the assignment.
Exercise
You deploy a new custom field Account.Region_Code__c to production by itself. Sales users report they cannot see it. What is the cause, and what should the deployment have included?
Show answer
FLS is stored in permission sets and profiles, not on the field. No container grants access, so the field is hidden from non-admin users. The deployment should have included a permission set (or profile) with a fieldPermissions entry for Account.Region_Code__c, and that permission set must also be assigned to the Sales users.