Quick Start with Deploy and Retrieve
In this quick start, we add a custom field to an object in our org and then retrieve its metadata into our Salesforce project. Then, we make a simple edit to the field and deploy the changes back to our org.
First, let’s add a custom field in an org that you are connected to:
- From Setup, enter Object Manager in the Quick Find box, then select Object Manager.
- Click Account.
- Click Fields & Relationships.
- Click New.
- For data type, select Date, then click Next.
- Enter these field values:
- Field Label: Created On
- Description: Date of Account Creation
- Click Next, Next, and Save.
Now, let’s retrieve the metadata for this new custom field into our Salesforce project.
- Return to your Salesforce project and open Org Browser.
- Scroll down to Custom Objects and navigate to Account.
- Click the retrieve icon next to Account to run SFDX: Retrieve Source from Org.
- From the Activity Bar, click Explorer and navigate to
force-app/main/default/object/Account.
In the fields folder, a file named Created_On__c.field-meta.xml contains metadata for your new custom field.
The metadata is:
1<?xml version="1.0" encoding="UTF-8"?>
2<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
3 <fullName>Created_On__c</fullName>
4 <description>Date of Account Creation</description>
5 <externalId>false</externalId>
6 <label>Created On</label>
7 <required>false</required>
8 <trackFeedHistory>false</trackFeedHistory>
9 <type>Date</type>
10</CustomField>
Let’s now make a simple edit to this field and deploy our changes back to our org with a single click.
- Edit
Created_On__c.field-meta.xml and change the <required> tag value to true to indicate that this custom field is required.
- Right-click the
objects/Account folder and click SFDX: Deploy Source to Org.
- After the command has run successfully, go back to your org and check the details of the Created On custom field to confirm that it’s now a required field.