1.1 An important message

Open Developer Console

There are several ways to write code in Salesforce. For now, let’s use developer console. It is a very good tool for beginners. There are several reasons:

  1. It is Salesforce built-in tool so there is no need for installation or configuration.
  2. It has good syntax highlighting. And it also helps you with code indent.
  3. If you have any errors in your code, it will tell you right away.

So, let’s start using it.

Open Developer Console via Your Name > Developer Console, as shown.

developer-console


Write our first code

In the opening Developer Console, click ctrl + e. If you are using Mac, click cmd + e. This should open your Execute Anonymous Window. You can consider this as your playground for now. It should look like this:

anonymous-window

Type in the below code:


System.debug('I am determined to start learning Salesforce development today');
System.debug('Today is ' + Date.today());

Then click Execute. Find the log in your logs tab. Double click to open it. In the filtering input, type in ‘DEBUG’. Make sure it is capitalised as the filter is case sensitive.  The result should look something like below:

an-important-message

In the future, when I say look at the debug logs, it means open the debug log and filter it with ‘DEBUG’. I will not explain the details in the future.


A little explanation: 

The code should be pretty straight-forward. But I will explain a little in details.

System.debug(), here System is the namespace. But you don’t need to worry about it for now. Just consider System.debug() means type the information out in the debug log.

Date.today() means today’s date. You don’t need to worry about the grammar for now.

Every statement in Apex need to end with ; This is the same as many other programming languages like Java and C#. In Apex, break lines doesn’t mean much unless it is in a quoted string. Only ; means it is an end to the current statement.


Exercise:

Write a piece of code to display ‘Hello, my name is Lance. This is my first day of learning Apex.’ Please replace Lance with your own name here. You should be able to see the result in your debug log.

Next Post:

1.2 An introduction to Developer Console

Subscribe to Sfdcinpractice

Subscribe to get the latest blogs and tutorials of sfdcinpractice. No spam, no trash, only the awesome posts from sfdcinpractice. 

#Apex#Tutorial

Leave a Reply

Your email address will not be published / Required fields are marked *