0

I saw the following example in the Salesforce Docs for creating fields using the metadata api: My question is - How does the system know to create a field on the account standard object? I cannot find anything that indicates that this xml file will deploy the fields onto the Account Standard object? I think I just do not understand how the file structure of these xml files works.

The following is the definition for two fields on the Account standard object—a custom field (MyCustomAccountField__c), and a standard field (Phone) that has history tracking enabled.

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <fields>
        <fullName>MyCustomAccountField__c</fullName>
        <description>A custom field on the Account standard object.</description>
        <externalId>false</externalId>
        <inlineHelpText>Some help text.</inlineHelpText>
        <label>MyCustomAccountField</label>
        <length>100</length>
        <required>false</required>
        <trackFeedHistory>false</trackFeedHistory>
        <trackHistory>false</trackHistory>
        <type>Text</type>
        <unique>false</unique>
    </fields>
    <fields>
        <fullName>Phone</fullName>
        <trackFeedHistory>false</trackFeedHistory>
        <trackHistory>true</trackHistory>
    </fields>
</CustomObject>
5

In the provided example, the core thing to bound this field to account is naming of .xml file.

It will be Account.object-meta.xml. Therefore, the fields in xml with such name will be added to Account.

It is also very important to deploy your archived xml files with proper names, so the organization understands what you want from it.

  • I have a custom object called "Top of the Funnel Trending" with the developer name "Top_of_the_Funnel_Trending__c" - would this be Top_of_the_Funnel_Trending__c.Object-meta.xml? – Matthew Metros Oct 17 at 14:01
  • Yes, you are right, except for object in the lower case. – Mariia Illarionova Oct 17 at 14:02
  • So what would the zip file look like? Just a zip with - Top_of_the_Funnel_Trending__c.object-meta.xml? – Matthew Metros Oct 17 at 14:03
  • 1
    @MatthewMetros You would have a package.xml that names the Account CustomObject (standard objects are also named as custom objects in the Metadata API), a folder called objects, and a Account.object-meta.xml file in the objects folder. – sfdcfox Oct 17 at 14:06
  • @MatthewMetros The comment above clearly describes the process. However, you can use sfdx commands to simplify the process. Open the terminal, go to the folder with your project. 1) mkdir mdapi 2) sfdx force:source:convert -d mdapi/ 3) sfdx force:mdapi:deploy -d mdapi/ -u YOUR_USER_NAME@example.com – Mariia Illarionova Oct 17 at 14:09

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.