22

How can I retrieve custom fields from standard objects using:

sfdx force:source:retrieve -m

I tried using CustomField to no avail.

I am trying to pull the custom fields I have added from a non-tracked org (i.e. a non-scratch org) that only supports MDAPI directly into the newer SFDX format.

3
  • 2
    This seems like a pretty clearly asked question. Why is this closed as "unclear"?
    – torpy
    Oct 8, 2019 at 15:27
  • 2
    I've noticed this trend quite some time ago. Mods that never had any serious exposure to certain aspects of Salesforce have no idea about the question. Particularly bad when asking developer questions and clueless admins kill questions down. Also super annoying when people ask for code samples when question was clearly a conceptual one.
    – dzh
    Oct 11, 2019 at 4:48
  • Yeah this was closed by the community, not a moderator. Going to re-open it because was about to ask this exact question myself, it has all the information it needs.
    – Matt Lacey
    Jan 21, 2020 at 0:10

2 Answers 2

26

This syntax was what I needed

sfdx force:source:retrieve -m CustomField:Claim.CveClaim__c

to retrieve my custom field CveClaim__c that I added to the (standard in FSC object) Claim. The -m CustomObject:Account will pull back all the fields of that object - standard and custom.

6
  • I know this wasn't the original question, but I can't get this to work with custom fields on custom objects. I just get "No results found". Has anyone found a way to retrieve source for custom fields on custom objects without having to retrieve the entire custom object including all its fields?
    – Frans
    Sep 16, 2021 at 10:49
  • 1
    Hi @Frans, I would expect it to work: have you got the right namespace prefix on the object name and field name?
    – Keith C
    Sep 16, 2021 at 11:39
  • I would expect many things to work on Salesforce, and particularly on DX, that just don’t. This is apparently one of them.
    – Frans
    Sep 17, 2021 at 20:42
  • For anyone that still trying to get custom fields on custom objects. I was able to get a custom field from a custom object in a managed package using the command: sfdx force:source:retrieve -m CustomField:packagenamespace__CustomObject__c.MyField__c
    – Leto
    May 1, 2022 at 9:27
  • This definitely works with custom objects. My example: sfdx force:source:retrieve -m CustomField:Employee_Profile__c.Last_Submitted_Timesheet__c
    – Shanerk
    Sep 13, 2022 at 20:14
4

You have to specifically name the objects you want, e.g. -m CustomObject:Account,Opportunity

Alternatives I know of:

1) Use this VSCode plugin to easily produce a package.xml by point and click, then retrieve against that.

https://marketplace.visualstudio.com/items?itemName=VignaeshRamA.sfdx-package-xml-generator

2) Use shane-sfdx-plugins which supports a syntax sfdx shane:mdapi:pull --type=CustomObject but will actually pull standard objects too.

https://github.com/mshanemc/shane-sfdx-plugins

4
  • 2
    As I can't post this more clearly because the question is closed, let me add that this syntax was what I needed sfdx force:source:retrieve -m CustomField:Claim.CveClaim__c to retrieve my custom field CveClaim__c that I added to the (standard in FSC object) Claim. The -m CustomObject:Account will pull back all the fields of that object - standard and custom.
    – Keith C
    Sep 27, 2019 at 17:51
  • That's fine if you want all the fields of the object, but sometimes it's more desirable to pull just the specific field from the object. In which case Keith C has provided a nice example of what command to use.
    – torpy
    Oct 8, 2019 at 15:29
  • 1
    @KeithC Can you post this as an asnwer now? I just re-opened the question and your comment here is the exact answer I was after. Also, ping me when you do so I can up-vote :)
    – Matt Lacey
    Jan 21, 2020 at 0:11
  • @MattLacey Done.
    – Keith C
    Jan 21, 2020 at 8:39

You must log in to answer this question.

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