Salesforce CLI in xycode

Posted by ExiaHuang on December 19, 2019

Agenda

Use xycode and Salesforce CLI to develope sfdc.

config

Config for windows user: xycode.sfdx.json

Config for linux user: xycode.sfdx.json

Config for mac user: xycode.sfdx.json

Solution

Create a project

force:project:create

xycode-sfdx-init-project

Authentication

force:auth:web:login

Retrieve metadata

force:source:retrieve:metadata

xycode-sfdx-retrieve-meta

Deploy metadata

force:source:deploy:metadata force:source:deploy:current_file

Diff metadata

force:source:diff:metadata

You can diff with any sfdc organization.

diff source

xycode-sfdx-diff-meta

diff profile

xycode-sfdx-diff-profile-meta

Useful Tips

auto run apex anonymous code

auto run apex anonymous code after save .apex.

change the config: ~/.xycode/xycode.sfdx.json set inActive false as below.

1
2
3
4
5
6
7
8
9
10
"onSaveEvents": [
    {
        "label": "auto run apex anonymous code.",
        "description": "run apex anonymous code after save.",
        "filetypes": [".apex"],
        "cwd": "${fileDirname}",
        "inActive": false,
        "command": "sfdx force:apex:execute --apexcodefile \"${file}\""
    }
]

also, you can write a command and run .soql after you save.

xycode-sfdx-run-apex-anonymous

pretty apex code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    "onSaveEvents": [
        {
            "label": "pretty apex code.",
            "description": "use prettier-plugin-apex to format salesforce apex code. npm install --global prettier prettier-plugin-apex ",
            "filetypes": [".trigger", ".cls"],
            "cwd": "${fileDirname}",
            "inActive": true,
            "command": "prettier --parser=apex --write \"${file}\" --tab-width=4 --single-quote=true"
        },
        {
            "label": "pretty apex anonymous code.",
            "description": "pretty apex anonymous code",
            "filetypes": [".apex"],
            "cwd": "${fileDirname}",
            "inActive": true,
            "command": "prettier --parser=apex --write \"${file}\" --tab-width=4 --single-quote=true --apex-anonymous"
        },

    ]