Salesforce Apex Tutorial – Chapter 2: Apex Environment
Salesforce Provides Sandbox and Developer Editions organization to develop Apex Code, you can use either of them for apex code development. A sandbox is a replica of the production environment in which you can build and test your code before deploying it to the production environment as it reduces the risk of getting errors in production.
Before reading this tutorial, you can read Salesforce Apex Tutorial – Chapter 1: Apex Overview as first tutorial. You can read the Salesforce Apex Tutorial – Chapter 3: Apex Examples.
It is a salesforce best practice to use the Sandbox environment for developing code and then deploy it to the Production environment. The operations you perform in your sandboxes are not reflected in your Salesforce production organization. Salesforce provides four types of sandboxes i.e,
- Developer Sandbox.
- Developer Pro Sandbox.
- Partial Data Sandbox.
- Full Sandbox.
Sandboxes are available per salesforce edition type; it depends on what edition you have.
|SANDBOX TYPE||PROFESSIONAL EDITION||ENTERPRISE EDITION||UNLIMITED EDITION||PERFORMANCE EDITION|
|Developer Pro Sandbox||5||5|
|Partial Copy Sandbox||Not Available||1||1||1|
|Full Sandbox||Not Available||1||1|
Apex Code development tools: The following is a list of three tools that are available to develop apex code in all Salesforce editions.
- Force.com Developer Console
- Force.com IDE
- Code Editor in the Salesforce User Interface
Let’s take a look at working of the Force.com developer console
Force.com Developer Console
A Developer Console provides a set of tools you can use to develop, debug, and test applications within your Salesforce organization. It is an integrated development part of the salesforce organization.
Following are the steps to be followed to use the developer console:
Go to Setup and click on developer console from the drop-down in lightning framework, It will open it in a new window as shown in the below pics:
Here’s a list of operations you can perform using the developer console.
- Code writing and compilation of code: you can create an apex class, trigger, lightning component or visualforce page, etc using the source code editor and as soon as you save your code it will automatically be compiled on the force.com server.
- Debugging: Apex supports debugging. Using the Developer Console and the debug logs, you can debug Apex code and also you can set checkpoints to make debugging easier.
- Testing: You can build and execute test cases for a specific apex class and also inspect the code coverage.
- SOQL/SOSL queries: In the query editor tab you can perform both SOQL and SOSL queries.
- Color coding and autocomplete: In addition to auto-completion for class and method names, the editor uses a color scheme to make code elements easier to read.
Code execution steps in Developer Console:
Follow these steps to execute your code in the developer console.
Step 1: Open the Developer console from the setup.
Step 2: Click on Debug tab and select Open Execute Anonymous window or press CTRL+E directly to open the anonymous window
Step 3: A new window will appear in which you can write or paste the code and execute it as a whole or a highlighted piece of code and tick the checkbox open log as shown in the below image.
Step 4: After clicking Execute OR Execute Highlighted, debug log will open in which you can get all the details of success or failure of code.
Above steps should be followed to execute your code using force.com developer console.