Skip to main content

SF-0260 · Concept · Easy

What is apex?

✓ Verified by Vikas Singhal · Last reviewed 5/17/2026 · Updated for Spring '26

Apex is Salesforce’s strongly-typed, object-oriented programming language, designed specifically to run on the Lightning Platform (formerly Force.com). It looks a lot like Java — classes, interfaces, generics, exceptions — but with first-class access to the Salesforce database and runtime.

Why Salesforce built its own language

Apex isn’t Java, isn’t JavaScript, isn’t Python. Salesforce built it because the platform is multi-tenant: your code shares CPU, memory, and database resources with thousands of other orgs running on the same servers. A generic runtime would let any tenant’s bad code take everyone else down. Apex’s runtime is heavily instrumented — every query, every loop, every DML statement is metered against governor limits — so a tenant can’t monopolise shared resources.

What you can do with it

  • Trigger code on data changesbefore insert, after update and so on
  • Expose REST and SOAP endpoints to external systems
  • Write batch and queueable jobs for long-running work that exceeds synchronous limits
  • Build Visualforce controllers and Lightning component server-side methods (@AuraEnabled)
  • Send and receive email, schedule jobs, call out to external APIs
  • Write unit tests (the platform requires 75% code coverage to deploy to production)

What an Apex class looks like

public with sharing class AccountService {
    public static List<Account> getActiveAccounts(Integer maxRows) {
        return [
            SELECT Id, Name, Industry
            FROM Account
            WHERE Active__c = true
            ORDER BY CreatedDate DESC
            LIMIT :maxRows
        ];
    }
}

A few things specific to Apex you can see here:

  • with sharing — the class respects the running user’s sharing rules. The alternatives are without sharing (ignore them, useful for system-level work) and inherited sharing (use whatever the caller set).
  • [SELECT … FROM Account]SOQL is inline, parsed and validated at compile time. No SQL injection-by-default, no ORM layer to learn.
  • :maxRows — bind variables. The colon is the Apex way to safely inject a runtime value into a SOQL statement.

What interviewers are really looking for

When someone asks “what is Apex?” in an interview, they’re rarely after the dictionary definition. The signal they want is whether you understand that Apex is a constrained language — constrained on purpose. Mention multi-tenancy, governor limits, and the fact that Apex runs in a transaction-aware sandbox, and you’ve answered the real question.

Common follow-ups

  • When should you use Apex over Flow? — see When should we use Apex?
  • What’s the difference between with sharing and without sharing?
  • What are governor limits and how does Apex enforce them?

Verified against: Apex Developer Guide — Introducing Apex, Trailhead module Apex Basics for Admins. Last reviewed 2026-05-17 for Spring ‘26 release.