Hi All,
Salesforce has built nice tools you can work with APEX. But when there are complex coding going on you probably prefer an IDE rather than the online developer console.
And why would you need an IDE over online developer console?
Well, for me its the powerful intellisense.
So as you know Salesforce has built a plugin for Eclipse IDE but now it is deprecated and now Salesforce has built much powerful extension for Visual Studio Code.
I'll explain you how to set up this and how to link it with your online Salesforce environment.
1. Download and install Visual Studio Code. Download from here
2. Download and install JDK (Java Development Kit). Download from here
3. Download and install Sslesforce CLI. Download it from here
4. Install Salesforce Extension Pack for VS Code
4.1 Open VS Code and go to Extensions section and search 'Salesforce Extension Pack'
4.2. Click on Install
5. Restart VS Code when the installation is completed.
Once you have installed the above mentioned tools, then you can start linking with your project in Salesforce with VS Code.
There are 2 types of developer processes or models:
1. Org Development Model
2. Package Development Model
Org Development Model
The org development model allows you to connect directly to your sandbox, Developer Edition (DE) org, Trailhead Playground, or even a production org to retrieve and deploy code directly.
Package Development Model
This model allows you to create self-contained applications or libraries that are deployed to your org as a single package.
You can read more about these models from here
Connect to your Org directly from VS Code
Since we are going to directly connect to your Salesforce Org, we are going to use Org Development Model.
1.2. Give a project name when it prompts
1.3. Select the location to save your project in the drive
2.2. Select your desired environment. (I select Project Default).
2.3. Enter Org Alias or just press Enter from the next prompt.
2.4. Then the browser will open up with Salesforce login. Login to your desired Salesforce account to be linked.
2.5. Then some undergrounds task will be run to connect with your localhost project and the browser will show 'cannot open the page' message. Then close the browser and go to your VS Code.
NOTE: If you are keep getting redirected to the Salesforce login page even when you entered your correct credentials, try restarting the machine and continue with the step 2.1
If it successfully completed the authentication, in VS Code you will see following message and output.
If you are connected to a sandbox, DE org, or Trailhead Playground, the easiest way to retrieve all the metadata you want to work with from your org is by using a package.xml file.
In order to get the changes from the Org environment, Right click on the package.xml under manifest and select SFDX: Retrieve Source in Manifest from Org
Then your project will retrieve the changes that you have done in your linked Org.
And when its successful, you will get the following output according to your changes.
In my case I have created some APEX classes and trigger and those are retrieved.
You can do this by right clicking on the package.xml and selecting SFDX: Deploy Source in Manifest to Org
So now you can realize the different when writing APEX code with VS Code.
Online Developer Console: No intellisense
And VS Code with Salesforce extension; there you go !
Happy coding !!
Salesforce has built nice tools you can work with APEX. But when there are complex coding going on you probably prefer an IDE rather than the online developer console.
And why would you need an IDE over online developer console?
Well, for me its the powerful intellisense.
So as you know Salesforce has built a plugin for Eclipse IDE but now it is deprecated and now Salesforce has built much powerful extension for Visual Studio Code.
I'll explain you how to set up this and how to link it with your online Salesforce environment.
1. Download and install Visual Studio Code. Download from here
2. Download and install JDK (Java Development Kit). Download from here
3. Download and install Sslesforce CLI. Download it from here
4. Install Salesforce Extension Pack for VS Code
4.1 Open VS Code and go to Extensions section and search 'Salesforce Extension Pack'
4.2. Click on Install
5. Restart VS Code when the installation is completed.
Once you have installed the above mentioned tools, then you can start linking with your project in Salesforce with VS Code.
There are 2 types of developer processes or models:
1. Org Development Model
2. Package Development Model
Org Development Model
The org development model allows you to connect directly to your sandbox, Developer Edition (DE) org, Trailhead Playground, or even a production org to retrieve and deploy code directly.
Package Development Model
This model allows you to create self-contained applications or libraries that are deployed to your org as a single package.
You can read more about these models from here
Connect to your Org directly from VS Code
Since we are going to directly connect to your Salesforce Org, we are going to use Org Development Model.
1. Create new project
1.1. Open command pallet in VS Code and run SFDX: Create Project with Manifest1.2. Give a project name when it prompts
1.3. Select the location to save your project in the drive
2. Autorize an Org
2.1. Open command pallet in VS Code and run SFDX: Authorize an Org2.2. Select your desired environment. (I select Project Default).
2.3. Enter Org Alias or just press Enter from the next prompt.
2.4. Then the browser will open up with Salesforce login. Login to your desired Salesforce account to be linked.
2.5. Then some undergrounds task will be run to connect with your localhost project and the browser will show 'cannot open the page' message. Then close the browser and go to your VS Code.
NOTE: If you are keep getting redirected to the Salesforce login page even when you entered your correct credentials, try restarting the machine and continue with the step 2.1
If it successfully completed the authentication, in VS Code you will see following message and output.
3. Retrieve Source
The Manifest (package.xml) fileIf you are connected to a sandbox, DE org, or Trailhead Playground, the easiest way to retrieve all the metadata you want to work with from your org is by using a package.xml file.
In order to get the changes from the Org environment, Right click on the package.xml under manifest and select SFDX: Retrieve Source in Manifest from Org
Then your project will retrieve the changes that you have done in your linked Org.
And when its successful, you will get the following output according to your changes.
In my case I have created some APEX classes and trigger and those are retrieved.
4. Publish changes to source
As you use 'SFDX: Retrieve Source in Manifest from Org' to retrieve changes, you have to publish when you done any changes in your local Org.You can do this by right clicking on the package.xml and selecting SFDX: Deploy Source in Manifest to Org
So now you can realize the different when writing APEX code with VS Code.
Online Developer Console: No intellisense
And VS Code with Salesforce extension; there you go !
Happy coding !!
Comments
Post a Comment