Skip to content

Mandatory custom field can not be in a profile/permission set

Detection

  • RegExp: Error (.*) You cannot deploy to a required field: (.*)

Examples

  • Error Admin You cannot deploy to a required field: Account.Code__c

Resolution

{1} sets the access of the required field {2}: a required field is always readable and editable, so its access can not be deployed.
- Remove the <fieldPermissions> block of {2} from {1}
- If {2} is required in the target org only, add a replacement rule that removes it before each deployment to the orgs that refuse it (https://sfdx-hardis.cloudity.com/salesforce-devops-config-replacement-rules/):
  sf hardis:project:replacement:create --agent --layer project --id remove-required-field-access --type xml-remove --files "**/profiles/*.profile-meta.xml" --xml-path "Profile/fieldPermissions[field={2}]" --include-branches TARGET_BRANCH

Example of element to delete:
<fieldPermissions>
  <editable>true</editable>
  <field>{2}</field>
  <readable>true</readable>
</fieldPermissions>

Comments