HubFirms : Blog -The best way to learn Apex coding in Salesforce

The best way to learn Apex coding in Salesforce

The best way to learn Apex coding in Salesforce

The Salesforce administrator can have in their back pocket essential knowledge on the Salesforce Apex programming language. This mindfulness enables overseers to more readily comprehend the conduct of an application. Thus, administrators can disclose hidden logic to clients as well as analyze issues without setting off to a Salesforce developer for help. To help Salesforce administrators, one should learn Apex coding. I prescribe composing a Hello World program. In this post, I will walk you through it. All the while, you will become familiar with a couple of basic yet valuable programming ideas: features, syntax, and learning resources to learn Apex programming language.

Let us first understand what Apex is?

Apex is a strongly typed object-oriented programming language that is used to develop applications on top of the Salesforce platform. Apex is a case insensitive language. Using Apex, you can write the custom business logic on the Salesforce platform which can be executed on different occasions. Apex is saved, compiled, and executed on the console only not on the client system. This means you don’t need to install any development kit, compiler or interpreter on your client system to write the Apex code.

Java for iOS? Gluon Client plugins support Java & JavaFX on iOS devices

Salesforce Apex is intended to process a lot of information to add business logic to applications and to compose the Controller in the MVC design. Declarative programming and Programmatic advancement are the two Application development types in Salesforce.

Flows of action involved in Apex

Developer action

This is for the developer to perform development or coding work

End-user action

This is for the end-user or the business user

What features does Apex programming language include?

  • Salesforce offers Data manipulation language (DML) with worked in exception handling
  • Salesforce Object Query Language (SOQL) and Salesforce Object Search language (SOSL) are utilized to question and recover information
  • Apex in Salesforce has worked in the record-locking system. This forestalls record update conflicts
  • Salesforce Apex programming language runs on multi inhabitant Environment
  • Apex code is stored in Metadata design
  • It has Java like syntax and variables
  • It furnishes unit testing and test execution with code inclusion
  • At the point when we need to add web and Email administrations to your Application
  • It is utilized to perform complex business forms
  • When we can add complex validation rules to your application
  • Salesforce Apex can be utilized to include a custom logic like saving a record

Syntax of Apex

Following are the syntax declaration of Apex in various means: -

How can we declare a variable in Apex?

Apex is a strongly typed language. Thus, it is necessary to declare a variable with data type in apex. In the following code snippet, the variable con is declared with contact as a datatype.

contact con = new contact();


New Java proposal: JEP draft explores Java syntax with hyphenated keywords

How to write a SOQL Query?

SOQL stands for Salesforce Object Query Language. It is used to fetch sObject records from the backend of Salesforce. The below query fetches the account record from the backend of Salesforce:

Account acc = [select id, name from Account Limit 1];

How to write Loop Statement?

A Loop statement is used to iterate the records in a mentioned list. In the looping structures, the number of iterations is equal to the number of records in the list.

list<Account>listOfAccounts = [select id, name from account limit 100];

// iteration over the list of accounts

for(Account acc : listOfAccounts) {

//your logic


How to write a Flow Control Statement?

These statements are beneficial when you want to execute a few lines of code. The following code is used to query account records from the backend and will check the list size.

list<Account>listOfAccounts = [select id, name from account limit 100];

// execute the logic if the size of the account list is greater than zero

if(listOfAccounts.size() >0){
    //your logic


How to write a DML Statement?

DML means Data Manipulation Language. These statements are used to manipulate data in the backend of Salesforce.

Account acc = new Account(Name = ‘ Test Account’);

Insert acc; // DML statement to create account record.

Writing ‘Hello World!’ program in Apex

Before we can begin coding our Hello World program, we have to figure out how to run it. There are a few different ways to execute Apex coding and programming on the Salesforce stage. There are three ways of creating apex classes in Salesforce: 

1) Developer Console 
2) IDE and, 
3) Apex class detail page

Javalin 2.8.0 arrives with Micrometer support and important Misc fixes

The least complex one is utilizing the Developer Console to execute code in an anonymous block. We should begin by opening the console. Follow the steps below-

  1. Ensure your profile has the "Creator Apex" permission enabled. 
  2. Click on the gear symbol, at that point select Developer Console. In the event that you are in classic mode, click on your name on the upper right, at that point select Developer Console. 
  3. When the Developer Console loads, click debug on the menu and select Open Execute Anonymous Window. You can likewise utilize the alternate route by pressing CTRL+E. 
  4. Type the following line of code: System.debug (‘Hello World!’);
  5. Check the Open Log option. 
  6. Click Execute. 
  7. When the Execution Log loads, check the Debug Only checkbox. 
  8. You should see your Hello world message. 

Congrats, you just composed your first Salesforce Apex program!

Key resources to learn Salesforce

  • Training and certification in Salesforce

Salesforce Certification has a comprehensive schedule of authority and network occasions throughout the world, including its yearly Dreamforce conference in San Francisco, Salesforce World Tour, and Salesforce Basecamp. These occasions offer an open door for you to finish training or go to wise workshops on Salesforce technology.

  • Cheat Sheet

Cheat sheets are a valuable tool for a snappy reference on particular topics. There are over twelve cheat sheets accessible about different areas inside the Salesforce biological system. They're all brief and simple to process. 

  • Developer Workbooks

This is an extraordinary asset for developers where you can discover incredible instructional exercise manuals on an assortment of applicable themes. Exercise manuals incorporate, Apex, Visualforce, and considerably more. 

  • Tip Sheets and Implementation Guides

You can use various blogs on the internet to see supportive tips and usage manages that depict various highlights and abilities of the Salesforce stage.

  • User Guides

Look at these effectively downloadable Salesforce guides for your adapting needs. They spread points for apprentices, deals and advertising, administration and backing, networks and cooperation, investigation and the sky's the limit from there.

  • Salesforce Glossary

This is a definitive rundown of terms you must realize when working with Salesforce. This is an especially decent asset for those previously working in the field however hoping to create or invigorate their insight.

  • Salesforce specialists

Salesforce urges their experts to impart knowledge to the network and help other people learn. Numerous Salesforce experts have sites that are as often as possible refreshed with valuable data, how-tos, and tips. If you utilize the hashtag #askforce, the Salesforce Ohana will be glad to help with questions about the Salesforce stage.

Take a step ahead

There are many other tools for learning Salesforce development. Salesforce makes it easy for developers to learn and develop Salesforce apps with ease. As per career prospects, Salesforce is leading there too. You can take a step ahead of your Salesforce career with Salesforce online training.

5 Different Ways to Create Objects in Java


Author Biography.

Digvijay Upadhyay
Digvijay Upadhyay

Digvijay Upadhyay has over 7+ years of experience in Technology content writing at JanBask. Digvijay is specialized in writing on the web technology & services, website design & development, digital marketing, Education & career, technology trends and write other valuable IT topics for online audience.

Related Posts