Apex - Environment
Apex programming tutorial
Apex - Environment
In this chapter, we will understand the environment for our Salesforce Apex development. Assume you already have a Salesforce edition set up for Apex development.
You can develop Apex code in the Sandbox or Developer edition of Salesforce. A sandbox organization is a copy of your organization where you can write code and test it without taking the risk of modifying data or disrupting normal operation. As per standard industry practice, you should develop the code in Sandbox and then deploy it to the production environment.
For this tutorial, we'll be using the Developer Edition of Salesforce. In Developer Edition, you will not have the option to create a Sandbox org. Sandbox features are available in other editions of Salesforce.
Apex Code Development Tools
In all editions we can usewill be one of the following three tools for developing code -
- Force.com Developer Console
- Force.com IDE
- Code Editor in the Salesforce UI
Note - We will be using the Developer Console throughout our tutorial for the code execution because it is simple and user-friendly for learning.
Force.com Developer Console
The Developer Console is an integrated development environment with a set of tools that you can use to build, debug, and test applications in your organization Salesforce.
Follow these steps to open the Developer Console -
Step 1 - Go to Name → Developer Console
Step 2 - Click on "Developer Console " and a window will appear like in the following scr eenshot.
Here are some operations that can be performed using the Developer Console.
Writing and compiling code - You can write code using editur source code. When you register a trigger or a class, the code is automatically compiled. All compilation errors will be reported.
Debugging - You can write code using the source code editor. When you register a trigger or a class, the code is automatically compiled. All compilation errors will be reported.
Test - You can view debug logs and set checkpoints that facilitate debugging.
Performance Check - You can run tests of specific test classes or all classes in your organization, and you can view the results tests. You can also inspect the code coverage.
SOQL Queries - You can inspect the debug logs to locate performance bottlenecks.
Ccolor coding and autocomplete - The source code editor uses a color scheme for easier readability of code elements and provides autocomplete for class and method names.
Running Code in the Developer Console
All of the code snippets mentioned in this tutorial should be run in the Developer Console. Follow these steps to complete the steps in the Developer Console.
Step 1 - Log into Salesforce.com using login.salesforce.com . Copy the code snippets mentioned in the tutorial. For now, we'll use the following sample code.
String myString = 'MyString '; System.debug ( 'Value of String Variable ' + myString);
Step 2 - To open the Developer Console, click on Name → Developer Console then c click on Run Anonymous as shown below.
Step 3 - In this step a window will appear and you can paste the code into it.
Step 4 - When we click on Run , the debug logs will open. UOnce the log appears in the window as shown below, click on the log record.
Then type 'USER ' in the window as shown below and the exit instruction will appear in the window of debugging. This 'USER ' instruction is used to filter the output.
So basically you will follow all the above mentioned steps to run any snippet in this tutorial.