Getting Started with Apex · Lesson 1 of 41
What Is Apex in Salesforce?
Apex is Salesforce's own programming language. It looks a lot like Java, it runs on Salesforce's servers, and it's built for one job: adding business logic to your Salesforce data that clicks-not-code tools can't handle cleanly. When a sales process needs complex validation across several objects, an integration with an ERP, or a nightly job over a million records, Apex is the tool.
This course takes you from your first line of Apex to the patterns used in large production orgs. Every example with a result panel was run in a real Salesforce org, so the output you see is what Salesforce actually printed.
In this lesson
- What Apex is and what makes it different from other languages
- Where Apex runs and how a request flows through it
- Apex vs Flow vs Lightning Web Components
- Your first piece of Apex
Apex in one paragraph
Apex is a strongly typed, object-oriented language that is compiled and executed on the Salesforce platform. You can't run it on your laptop: you write it locally, deploy it to an org, and it runs there. It has database access built into the language (queries in square brackets, insert and update as keywords), it runs inside transactions, and it's subject to governor limits – caps on how much each transaction may use, because thousands of companies share the same servers.
Where your Apex runs
- Your codeclasses, triggers, anonymous Apex, test classes
- Apex runtimecompiles your code, enforces governor limits, manages transactions
- Salesforce platform servicesdatabase, security model, metadata, automation (Flow), APIs
- Multitenant infrastructureshared servers and databases for many orgs (Hyperforce on public cloud)
What makes Apex different
| Feature | What it means in practice |
|---|---|
| Database-aware | SOQL queries and DML are part of the language: [SELECT Name FROM Account], insert contact; |
| Strongly typed | every variable has a type checked at compile time – fields and objects too, so a typo in a field name won't deploy |
| Object-oriented | classes, interfaces, inheritance – familiar if you know Java or C# |
| Transactional | all database changes in one request succeed or fail together |
| Governed | limits on queries, DML, CPU time and heap per transaction |
| Metadata-aware | the platform knows which code uses which fields, and blocks deleting a field your code uses |
| Case-insensitive | account, Account and ACCOUNT are the same identifier |
Where Apex is used
Ways your Apex gets called
- Triggersrun automatically when records are inserted, updated, deleted or undeleted
- Lightning componentsLWC calls @AuraEnabled methods to read and save data
- Asynchronous jobsfuture, Queueable, Batch and Scheduled Apex for heavy or delayed work
- Integrationscallouts to external APIs, and your own REST endpoints with @RestResource
- Flowinvocable methods give Flow builders actions written in Apex
Apex vs Flow vs LWC
Salesforce's advice is "clicks before code", and it's good advice: Flow is easier for admins to maintain. Apex earns its place when the logic gets complex, the data gets big, or you need full control.
| Choose… | When… |
|---|---|
| Flow | straightforward record automation, screens and approvals an admin should be able to change |
| Apex | complex logic, large data volumes, integrations, precise error handling, reusable services, anything that needs unit tests |
| LWC | the user interface – usually backed by Apex or Lightning Data Service |
In real projects they work together: a record-triggered Flow calls an invocable Apex method, an LWC calls an Apex controller, a trigger delegates to a service class. Learning Apex makes you better at deciding which tool fits.
Your first Apex
The quickest way to run Apex is anonymous Apex: a snippet executed once, without saving a class. Here's a small one that already uses three Apex strengths – types, a collection and a database query:
String course = 'Salesforce Apex';
Integer lessons = 41;
List<String> topics = new List<String>{ 'SOQL', 'DML', 'Triggers', 'Batch Apex' };
System.debug('Welcome to ' + course + ' – ' + lessons + ' lessons');
System.debug('First topics: ' + String.join(topics, ', '));
// Apex talks to the database directly
insert new Account(Name = 'LearnFrenzy Academy', Industry = 'Education');
Account acc = [SELECT Name, Industry FROM Account WHERE Name = 'LearnFrenzy Academy' LIMIT 1];
System.debug(acc.Name + ' is in ' + acc.Industry);
Welcome to Salesforce Apex – 41 lessons First topics: SOQL, DML, Triggers, Batch Apex LearnFrenzy Academy is in Education
Notice what you didn't need: no database connection, no SQL driver, no mapping from rows to objects. insert saved a record and the query in square brackets returned a typed Account. That tight integration is why Apex exists. (We'll set up the tools to run this yourself in the next lesson.)
Governor limits, briefly
Because your code shares servers with other companies, each transaction gets a budget. A few of the most important synchronous limits:
| Limit (per transaction) | Value |
|---|---|
| SOQL queries | 100 |
| Records returned by queries | 50,000 |
| DML statements | 150 |
| Records processed by DML | 10,000 |
| CPU time | 10 seconds |
| Heap size | 6 MB |
Exceed one and the transaction stops with an exception you can't catch. That sounds scary, but it simply means writing bulk-safe code – a habit this course builds from the first chapter. The full story is in governor limits.
How this course is organised
- Language basics – data types, strings, dates, operators, control flow, collections
- Object-oriented Apex – classes, interfaces, exceptions
- Data – sObjects, SOQL, SOSL, DML, transactions
- The platform – governor limits, bulkification, triggers, order of execution
- Asynchronous Apex – future, Queueable, Batch, Scheduled
- Quality and safety – testing, security
- Integration and pro patterns – LWC, callouts, platform events, design patterns, interview prep
Practice
Try it yourself
Your team needs to send every new high-value Opportunity to an external ERP system and retry if the ERP is down. Flow or Apex?
Show answer
Apex (typically a trigger that enqueues a Queueable job making the callout, with retry logic and tests). Flow can make HTTP callouts, but reliable retries, error handling and bulk processing are much easier to build and test in Apex.
Why can't you run Apex on your own computer?
Show answer
Apex is compiled and executed by the Salesforce platform, next to your org's data and metadata. Locally you only write and deploy it.
Quick check
Is Apex case-sensitive?
No – identifiers, keywords, and object and field names are case-insensitive.
What is anonymous Apex?
A block of Apex executed once without saving it as a class – ideal for experiments and scripts.
Why do governor limits exist?
Many orgs share the same servers; limits stop one transaction from using too many resources.
Summary
- Apex is Salesforce's strongly typed, object-oriented language that runs on the platform.
- Queries and DML are built in, and every request runs as a transaction.
- Use Flow for simple automation and Apex for complex logic, large data and integrations.
- Governor limits cap each transaction – write bulk-safe code from day one.
Finished this lesson?
Mark it complete to track your progress, then carry on with the next lesson.