1

Is there a simple way to use the sfdx CLI to retrieve and deploy new custom fields from one org to another?

Use case: Someone creates new custom fields in Production and want to deploy them easily to other sandboxes without having to go to change sets or doing a full sandbox refresh. Potential Approach: I know we can grab a new custom field via:

sfdx force:source:retrieve -m CustomField:Account.New_Custom_Field__c -u MyProductionOrg

But I am looking to also "grab" the relevant Profile FLS settings along with this field (but not the whole Profile metadata file), then figure I could deploy via something like:

sfdx force:source:deploy -m CustomField:Account.New_Custom_Field__c,Profile -u MySandboxOrg

What am I missing?

1

If you're using a Scratch Org, just force:source:pull, and the related profile settings will be retrieved.

If you're using a non-Scratch Org (Developer, Sandbox), retrieve the fields and profiles in one command:

sfdx force:source:retrieve -m CustomField:Opportunity.CustomField__c,Profile

That said, you should probably consider moving to Permission Sets (and Permission Set Groups), which is a lot more portable when you get to using Unlocked Packages.

  • That sfdx ... -m Profile ends up bringing in a bunch of other userPermissions as well as the FLS for that field. Does just deploying it right afterwards have the same effective result as doing the change set with the Custom Field and the Profiles (meaning only the FLS is adjusted)? I was under the impression that Change Set Custom field + Profile deploys only adjusted Profile FLS for that custom field, but again, seeing a lot of other permissions here. If it has the same effect as Change sets, I think this will work nicely – Brian Miller Aug 12 '20 at 21:59
  • Also like the idea of Permission Sets and Unlocked Packages, but a bit overkill for my simple use case. Just creating some audit datetime fields that everyone should have visibility on – Brian Miller Aug 12 '20 at 22:00
  • 1
    @BrianMiller The global permissions retrieved would also be deployed, but this shouldn't matter if you're pulling the profiles from, say, a Sandbox, since those should match production. However, only the retrieved fields will be included in the xml file. This is effectively the same behavior as change set behavior. – sfdcfox Aug 12 '20 at 23:50
  • This is perfect, thank you! – Brian Miller Aug 13 '20 at 0:15

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.