What Is Apex?
By the end of this lesson, you'll be able to:
- Understand what Apex is using simple real-world examples.
- Learn why Salesforce created Apex.
- Know where Apex code runs.
- Recognise when to use Apex instead of clicks (Flow).
- Write your very first Apex program.
- Understand that making mistakes is part of learning.
Prerequisites: None! 😊 This is your very first Apex lesson. You don't need to know programming before starting. If you can read, think logically, and enjoy solving puzzles, you're ready to learn Apex.
Meet Apex - Salesforce's Superpower
Imagine you own a giant toy shop.
Every day customers come into your shop to buy toys.
Most of the time, your staff know exactly what to do.
If someone buys a toy, they collect payment.
If someone returns a toy, they put it back on the shelf.
Everything works perfectly.
Now imagine one customer says:
"If I buy three LEGO sets, give me a free teddy bear."
Your staff don't know this special rule.
Someone has to teach them.
Salesforce works exactly the same way.
Salesforce already knows how to store customers, accounts, contacts and opportunities.
But every company has special rules.
Those special rules are written using Apex.
Think of Apex as teaching Salesforce new skills.
Without Apex, Salesforce only knows its default behaviour.
With Apex, Salesforce can do almost anything you imagine.
Why Did Salesforce Create Apex?
Imagine playing your favourite video game.
The game already has lots of features.
But what if you wanted dragons to fly faster?
Or every treasure chest to contain chocolate?
The game wasn't built to do that.
You would need to change the game's code.
Salesforce is exactly the same.
Every company is different.
A hospital works differently from a bank.
A school works differently from a supermarket.
Salesforce cannot predict every company's needs.
That's why Apex exists.
It allows developers to customise Salesforce for any business.
Banks use Apex.
Hospitals use Apex.
Airlines use Apex.
Schools use Apex.
If a company uses Salesforce, there is a good chance Apex is helping it work.
Where Does Apex Live?
Unlike games or websites that run on your own computer, Apex lives inside Salesforce's cloud.
Think about Google Drive.
Your files aren't stored on your laptop.
They are stored safely on Google's computers.
Salesforce works the same way.
When you write Apex, your code is uploaded to Salesforce.
Whenever someone clicks a button or saves a record, Salesforce runs your code on its own servers.
That means:
✔ You don't need your own server.
✔ You don't need to install anything special.
✔ Salesforce looks after the computers for you.
You only focus on solving problems.
When Should You Use Apex?
Salesforce already includes many powerful tools that require no coding.
These are called declarative tools.
Examples include:
• Flow
• Validation Rules
• Formula Fields
Always ask yourself this question:
"Can Salesforce already do this without code?"
If the answer is YES, use the declarative tool.
If the answer is NO, then Apex might be the right choice.
You normally use Apex when:
• The business rules are complicated.
• You need to connect Salesforce to another system.
• You need lots of calculations.
• You need to automate many records.
Good developers always choose the simplest solution first.
Think Like a Robot
Computers are very smart.
But they are also very literal.
Imagine you tell a robot:
"Go get my shoes."
The robot asks:
"Which shoes?"
"Where are they?"
"What colour?"
Computers think the same way.
They only do exactly what we tell them.
Programming is simply learning how to give clear instructions.
The better your instructions, the better your program works.
That's what Apex is.
A language for talking to Salesforce.
A minimal Apex class
public class HelloWorld {
public static void sayHello() {
System.debug('Hello, Salesforce!');
}
}
public class declares the class; static means you can call sayHello() without creating a HelloWorld instance first.
Exercise
Open the Developer Console, go to Debug > Open Execute Anonymous Window, and run: HelloWorld.sayHello(); — then check the debug log for your message.
Show hint
Look for a line starting with USER_DEBUG in the log output.
What is Apex? — Quick Check
Leaderboard
- 1. Monde Masiza 3/3
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
Apex is Salesforce's programming language. Think of it as giving instructions to a super-smart robot that works inside Salesforce. Whenever Salesforce doesn't know exactly what you want, Apex lets you teach it new tricks. By the end of this lesson you'll understand what Apex is, why it exists, and write your very first piece of Apex code.