Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 36 ยท Getting Started

What Is Salesforce Apex?

Learn what Apex is, where it runs inside Salesforce, what it is used for, and how it compares with Java, Flows and Lightning Web Components.

Salesforce is a cloud platform that companies use to track customers, sales, support cases and much more. Out of the box you can click together a lot of functionality with objects, fields and Flows. But sooner or later a business asks for something the point-and-click tools cannot express: a complicated pricing rule, a nightly data clean-up, a call to a payment service. That is where Apex comes in.

Apex is a strongly typed, object-oriented programming language that runs on Salesforce's own servers. Its syntax looks very much like Java, and it was designed to work with Salesforce data directly. This course teaches Apex and its front-end companion, Lightning Web Components (LWC), from the first line of code to a deployable project.

Honest note about the runner. Salesforce Apex only runs inside a Salesforce org (a cloud server you log in to). It cannot run in this page. Real Apex code in this course is shown in read-only blocks. Where an idea can be demonstrated, the runnable examples are Java stand-ins, labelled as such, that mimic the behaviour. Output is only shown for the stand-ins, which we ran for real.

What Apex is used for

Apex is a server-side language. You use it to:

  • React to data changes with triggers: "when an Opportunity is closed, create a follow-up Task".
  • Build business logic in classes that other code, Flows and screens can call.
  • Run heavy work in the background with batch jobs, queueable jobs and scheduled jobs.
  • Expose and consume web services: your own REST endpoints, and calls to outside APIs.
  • Power Lightning Web Components: the browser UI calls Apex methods to read and write data.
  • Send and receive email, and write tests that prove all of the above works.
flowchart LR
    U["User in browser<br/>(LWC)"] --> A["Apex classes"]
    T["Triggers<br/>(data changes)"] --> A
    F["Flows and<br/>scheduled jobs"] --> A
    A --> D[("Salesforce database<br/>objects and records")]
    A --> W["External web services"]

Apex sits in the middle: many things call it, and it talks to the database and to the outside world.

How Apex differs from Java

If you know Java, you will feel at home. A few differences matter from day one:

Topic Java Apex
Where it runs Any JVM Only on Salesforce servers
Case Case-sensitive Case-insensitive (Name and name are the same)
Database Needs JDBC/JPA Built in: SOQL queries and DML statements are part of the language
Resource limits Your hardware Governor limits enforced per transaction
Compilation You compile locally Code is saved to the org, which compiles it
Sets and Maps Standard library Built-in List, Set, Map types

Here is a first taste of real Apex. A class with one method that returns a greeting:

Java
public class Greeter {
    public static String greet(String name) {
        return 'Hello, ' + name + '!';
    }
}

Notice that strings use single quotes in Apex; double quotes are not allowed for string literals. That is the first surprise for Java developers, and it appears constantly.

A Java stand-in for the case rule

Because Apex ignores case in identifiers, account, Account and ACCOUNT mean the same thing. Java cannot do that, but a case-insensitive map shows the idea.

Java Stand-in (Java): case-insensitive names

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Apex, Flows or LWC: which one?

Salesforce gives you three main ways to build behaviour. A good developer picks the simplest one that works:

  1. Declarative tools (Flow, validation rules, formulas): use these first. They need no code and admins can maintain them.
  2. Apex: use it when the logic is complex, must handle large data volumes, needs transactions, or calls other systems.
  3. Lightning Web Components: use them to build custom user interfaces.

They combine well. A Flow can call an Apex method, and an LWC can call Apex to fetch data. You will see each combination later in the course.

Multi-tenancy in one sentence

Salesforce runs thousands of customers on shared hardware. To stop one customer's code from slowing everyone else down, the platform sets governor limits (for example, a maximum number of database queries per transaction). Your Apex must be written to stay inside them. Governor limits get their own lesson because they shape almost every design decision.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where does Apex code run?

    Apex is a server-side language. It is saved to a Salesforce org, compiled there and executed on Salesforce's multi-tenant servers.
  2. 2. Which is a valid Apex string literal?

    Apex strings use single quotes. Double-quoted strings are a compile error.
  3. 3. Why does Salesforce enforce governor limits?

    Salesforce is multi-tenant. Limits protect all customers on the same infrastructure from runaway code.
  4. 4. Which tool should you try first for simple automation?

    Declarative tools need no code and are easier to maintain. Move to Apex when the requirement outgrows them.

Summary

  • Apex is Salesforce's Java-like, server-side, strongly typed language with built-in database access.
  • It is case-insensitive and uses single-quoted strings.
  • Use it for triggers, business logic, background jobs, integrations and as the back end for LWC.
  • Governor limits keep a shared platform fair, and your code must respect them.
  • Prefer declarative tools when they are enough.

Next: Setting Up Your Developer Environment