[email protected]
Search…
Using Source Format

  • Why is source format necessary?
  • Converting from MDAPI to source format and vice versa
  • Utilizing source commands to retrieve and deploy
Time to Complete: 45 Minutes

  • Open new Visual Studio code window
  • Open a new folder where you wish to create the source format project
sfdx force:project:create -n dxatscale101-source -t empty

Utilise sfdx force:mdapi:convert command to convert the mdapi format into a local format known as 'source format'.This format makes working with metadata api modular and maintainable.
  • Go to mdapi project in vscode
  • Run the below command in the terminal
sfdx force:mdapi:convert -r mdapi -d <workspacelocation>\dxatscale101-source\dreamhouse-app
  • Run the sfdx force:mdapi:convert command
  • copy the .gitignore file and data folder from mdpai project root to source project root to dxatscale101-source repository
Observe the difference between mdapi and source format. Object Metadata is decomposed into multiple files, this helps when you have a large project with multiple objects having a large amount of fields. Tracking the changes in fields and record types is relatively easy and time saving.
All challenges from here on will use source format
  • Open the new source project in VSCode
  • Delete force-app folder
  • Replace force-app with dreamhouse-app in the sfdx-project.json file
{
"packageDirectories": [
{
"path": "dreamhouse-app",
"default": true
}
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "52.0"
}

  • Set Compliance Categorization as GDPR to all fields in Broker__c object
    • Open Playground
    • Setup --> Object Manager --> Search Broker in Object finder--> Fields & Relationships --> Email --> Edit --> set Compliance Categorization as GDPR
    • Follow this step in all the fields in the Broker object
  • Setup a path on property status
    • Setup --> Path Settings --> new path --> use below details on Name and Record Type page and click Next--> Fields and Text page no changes click next --> Activate the path and then click Finish
      Field
      Value
      Path Name
      Property Status
      API Reference Name
      Auto populated from path name
      Object
      Property
      Record Type
      Auto populated as Master
      Picklist
      Status
  • Add the property status path to Property record page
    • Open Dreamhouse app in App launcher
    • Open Properties Record tab and open any record
    • Click Setup gear Icon --> Edit page --> search path in component finder --> add the path component below the compact layout
    • Save the changes and click back

sfdx force:source:retrieve -u <playground-1> -x <path to package.xml>
​
sfdx force:source:retrieve -u <playground-1> -m <metadatatype:medataname>
​
sfdx force:source:retrieve -u <playground-1> -p <sourcepath to retrieve>
Take the time to discuss and understand these commands

  • Update all the fields in Property__c to change the Compliance Categorization from PII to GDPR
  • Let's add a Broker image to Broker card component in property detail page. Replace brokerCard.js and brokerCard.html with below snippet and create a new file brokerCard.css with below snippets
    brokerCard.html
    <template>
    <lightning-card title="Broker Details">
    <template if:true={property.data}>
    ​
    <lightning-button-icon
    icon-name="utility:expand_alt"
    slot="actions"
    onclick={handleNavigateToRecord}
    ></lightning-button-icon>
    <div class="slds-var-m-around_medium">
    <lightning-layout>
    <lightning-layout-item size="3">
    <img src={brokerImage}></img>
    </lightning-layout-item>
    <lightning-layout-item size="9">
    ​
    <lightning-record-form
    object-api-name="Broker__c"
    record-id={brokerId}
    fields={brokerFields}
    columns="1"
    ></lightning-record-form>
    </lightning-layout-item>
    </lightning-layout>
    </div>
    </template>
    <template if:true={property.error}>
    <c-error-panel
    friendly-message="Error retrieving data"
    errors={property.error}
    ></c-error-panel>
    </template>
    </lightning-card>
    </template>
    brokerCard.js
    import { LightningElement, api, wire } from 'lwc';
    import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
    import { NavigationMixin } from 'lightning/navigation';
    ​
    import BROKER_FIELD from '@salesforce/schema/Property__c.Broker__c';
    import BROKERIMAGE_FIELD from '@salesforce/schema/Property__c.Broker__r.Picture__c';
    import NAME_FIELD from '@salesforce/schema/Broker__c.Name';
    import PHONE_FIELD from '@salesforce/schema/Broker__c.Phone__c';
    import MOBILE_PHONE_FIELD from '@salesforce/schema/Broker__c.Mobile_Phone__c';
    import EMAIL_FIELD from '@salesforce/schema/Broker__c.Email__c';
    ​
    const PROPERTY_FIELDS = [BROKER_FIELD,BROKERIMAGE_FIELD];
    const BROKER_FIELDS = [
    NAME_FIELD,
    PHONE_FIELD,
    MOBILE_PHONE_FIELD,
    EMAIL_FIELD
    ];
    ​
    export default class BrokerCard extends NavigationMixin(LightningElement) {
    @api recordId;
    ​
    brokerFields = BROKER_FIELDS;
    ​
    @wire(getRecord, { recordId: '$recordId', fields: PROPERTY_FIELDS })
    property;
    ​
    get brokerId() {
    return getFieldValue(this.property.data, BROKER_FIELD);
    }
    get brokerImage() {
    return getFieldValue(this.property.data, BROKERIMAGE_FIELD);
    }
    ​
    handleNavigateToRecord() {
    this[NavigationMixin.Navigate]({
    type: 'standard__recordPage',
    attributes: {
    recordId: this.brokerId,
    objectApiName: 'Property__c',
    actionName: 'view'
    }
    });
    }
    }
    brokerCard.css
    img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    }

sfdx force:source:deploy -u <playground-1> -p dreamhouse-app -w 30
Once the metadata is successfully committed, commit your changes to the repo.

  • Create a new repo in your GitHub Account with the below highlighted details
  • Get the newly created repo URL
  • Follow the below commands in the order from your Terminal to publish your local repo
    git init
    ​
    git add .
    ​
    git commit -m "First commit"
    ​
    git remote add origin <new repo url you copied>
    ​
    git remote -v
    ​
    git push origin master

Congrats! Now you have understood how to create a new sfdx source project and convert an existing project into source format, and also understood the similarity between Source and MDAPI. Please note that source format is only a local decomposition done by the CLI and the Salesforce Org doesn't understand source format.
Copy link
On this page
Learning Objectives
Steps
Create a new source project using sfdx force:project:create command
Convert the mdapi project used in 'Deploy to a Sandbox' challenge to source format
Make the following changes in the org
Retrieve the changes in the org using one of the below sfdx force:source:retrieve commands (Use the -h flag to understand usage)
Make the following changes in the local source code
Deploy the changes to both the playground using sfdx force:source:deploy command (The reference to documentation is attached or use the -h flag to understand usage)
Create a new repo to publish your new source format project
Recap