VS Code Setup with ForceCode

VS CodeVS Code is the new direction that Salesforce is going for its code editor of choice.  The focus is on DX and Scratch Orgs.

Salesforce has its own extensions for working in the Salesforce DX environment.  Here is a link to Salesforce’s directions for setting that up: https://developer.salesforce.com/tools/extension_vscode

And here is a Trailhead: https://trailhead.salesforce.com/en/content/learn/projects/quick-start-lightning-web-components/set-up-visual-studio-code

I added those but needed the ability to work directly with Sandboxes which the Salesforce extensions don’t have, yet.  The ForceCode extension has solutions for that and much more.  This is how I set up VS Code to use ForceCode.

ForceCode is an extension that allows you to make a connection to your Salesforce instance.  Sandboxes of course.  It also has some nice tools for working with your code like running tests and displaying test results and code coverage.

First go to the VS Code site and download the app.

Screen Shot 2018-06-17 at 3.59.13 AM

Run through the basic install process and start the app.

Once the app is open we will need to get the extension.  Look for the Extensions icon on the left menu of the app.  It looks like a square surrounding a square. Screen Shot 2018-06-17 at 4.03.55 AM

Then search for ForceCode and click on the Install button.  You will need to click the Reload button once it is done installing.  The picture is of an earlier version.  Current version is 3.16.0.  So just go with the latest.

Screen Shot 2018-06-17 at 4.14.55 AM

So far everything is going according to plan.  Let’s connect it to a Salesforce instance.

There are a couple of ways to do this.  Here is the easiest:

  • From the top menu, click View > Command Palette… or Cmd(Ctrl)-Shift-p
  • Search for forcecode and select the Create Project menu option
  • We are prompted with a request to select a folder…  or you can create one…  Click Create Project.
  • The prompt for “Select a saved org or login to a new one…” comes up.
  • Then we get to choose between Production / Developer, Sandbox / Test or Custom domain.
    Screen Shot 2018-06-17 at 4.46.02 AM
    If you are using this to access your Trailhead Playgrounds then use Developer.
  • Do you want to Automatically deploy/compile files on save or when use the ForceCode menu…  I usually select Yes.
  • Bingo! We should see a message in the bottom of the editor as it tries to connect and then a success message.
    Screen Shot 2018-06-17 at 4.53.04 AM
  • If you are creating a new org then it will open a browser and have you login to the Salesforce instance you want to work with prompting you if you want to allow access.  This is SSO sign on and doesn’t need a token!

Now let’s get some files from the server.

There are a couple of ways to get files from the server with ForceCode.

  • Open Salesforce File
    This allows you to get singular files
  • Retrieve Package/Matadata
    This allows you to get designated files in a managed package file or to get all the files from the org.

I went with the package.xml option.  I just created a quick package.xml file in the root of the src directory.

<?xml version=”1.0″ encoding=”UTF-8″?>
  <types>
    <members>*</members>
    <name>ApexClass</name>
  </types>
  <types>
    <members>*</members>
    <name>ApexComponent</name>
  </types>
  <types>
    <members>*</members>
    <name>ApexPage</name>
  </types>
  <types>
    <members>*</members>
    <name>ApexTestSuite</name>
  </types>
  <types>
    <members>*</members>
    <name>ApexTrigger</name>
  </types>
  <version>42.0</version>
</Package>

Go back to the ForceCode Menu and select Retrieve Package/Metadata > Retrieve by package.xml.  Just like that you should see the files located in the src directory.

Hope this was helpful.  Please send your comments below if I missed anything or if there is something particular you are looking for.

More to come on VS Code…

6 thoughts on “VS Code Setup with ForceCode

  1. Great article! My team mate and I were using MavensMate + VSCode and it stoped working as of yesterday —July 16, 2019. Thanks to your post I could switch to ForceCome in a snap. Thank you!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s