Salesforce Apex Tutorial – Chapter 2: Apex Environment

Salesforce Apex Tutorial – Chapter 2: Apex Environment

On September 27, 2021, Posted by , In Salesforce Apex Tutorial, With Comments Off on Salesforce Apex Tutorial – Chapter 2: Apex Environment
Salesforce Apex Tutorial - Chapter 2 - Apex Environment Image 1
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 TYPEPROFESSIONAL EDITIONENTERPRISE EDITIONUNLIMITED EDITIONPERFORMANCE EDITION
Developer Sandbox      1025100100
Developer Pro Sandbox55
Partial Copy SandboxNot Available111
Full SandboxNot Available11
Salesforce Apex Tutorial - Chapter 2 - Apex Environment Image 2
Deployment

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:

Salesforce Apex Tutorial - Chapter 2 - Apex Environment Image 3
Salesforce Apex Tutorial – Chapter 2 – Apex Environment Image 3
Salesforce Apex Tutorial - Chapter 2 - Apex Environment Image 4
Salesforce Apex Tutorial – Chapter 2 – Apex Environment Image 4

Here’s a list of operations you can perform using the developer console.

  1. 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.
  2. 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.
  3. Testing: You can build and execute test cases for a specific apex class and also inspect the code coverage.
  4. SOQL/SOSL  queries: In the query editor tab you can perform both SOQL and SOSL queries.
  5. 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.

Salesforce Apex Tutorial - Chapter 2 - Apex Environment Image 5
Salesforce Apex Tutorial – Chapter 2 – Apex Environment Image 5

Step 2: Click on Debug tab  and select Open Execute Anonymous window  or press CTRL+E directly to open the anonymous window

Salesforce Apex Tutorial - Chapter 2 - Apex Environment Image 6
Salesforce Apex Tutorial – Chapter 2 – Apex Environment Image 6

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.

Salesforce Apex Tutorial - Chapter 2 - Apex Environment Image 7
Salesforce Apex Tutorial – Chapter 2 – Apex Environment Image 7

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.

Salesforce Apex Tutorial - Chapter 2 - Apex Environment Image 8
Salesforce Apex Tutorial – Chapter 2 – Apex Environment Image 8
Salesforce Apex Tutorial - Chapter 2 - Apex Environment Image 8
Salesforce Apex Tutorial – Chapter 2 – Apex Environment Image 8

Above steps should be followed to execute your code using force.com developer console. 

Comments are closed.