Salesforce Apex and LWC Tutorial
Learn Salesforce Apex and LWC step by step: 36 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
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.
- Setting Up Your Developer Environment Set up a free Salesforce Developer Edition org, the Developer Console, VS Code with Salesforce extensions and the sf CLI so you can write Apex today.
- Your First Apex Code and Debug Logs Write and run your first Apex with Execute Anonymous, print values with System.debug, read debug logs and understand log levels, with Java stand-ins.
- Execution Model and Governor Limits Understand Apex transactions, the order of execution and the key governor limits (SOQL, DML, CPU, heap) and how to stay inside them, with Java stand-ins.
Apex Basics
- Variables and Data Types in Apex Learn Apex variables and primitive data types (Integer, Long, Decimal, Boolean, String, Id), null handling, constants with final and type conversion.
- Strings, Numbers and Dates in Apex Work with Apex Strings, Decimals and the Math class, and build, compare and format Date and Datetime values, with runnable Java stand-ins for the logic.
- Collections: Lists, Sets and Maps in Apex Master Apex collections: ordered Lists, unique Sets and key-value Maps, with the methods, iteration patterns and bulk-friendly idioms every trigger relies on.
- Control Flow and Loops in Apex Learn Apex decision and loop statements: if/else, ternary, switch on values and types, for, for-each, while, do-while, break and continue, with stand-ins.
- SObjects and Fields in Apex Understand Salesforce objects, records and fields as Apex SObjects: standard and custom objects, field access, relationships, generic SObjects and the Schema class.
SOQL and DML
- SOQL Basics Learn Salesforce Object Query Language: SELECT fields FROM an object, LIMIT, inline queries in Apex, single-record queries and bind variables, with stand-ins.
- Filtering and Sorting with SOQL Filter SOQL results with WHERE, operators, LIKE, IN, date literals and ORDER BY, plus LIMIT and OFFSET paging, NULLS handling and dynamic filters, with stand-ins.
- Relationship Queries in SOQL Query related records in SOQL: child-to-parent dot notation, parent-to-child subqueries, custom relationship names, semi-joins and anti-joins, with Java stand-ins.
- Aggregate SOQL Summarise data with SOQL aggregate functions COUNT, SUM, AVG, MIN and MAX, GROUP BY, HAVING, ROLLUP and AggregateResult, with Java stand-ins.
- DML: Insert, Update, Delete and Undelete Save data with Apex DML statements insert, update, upsert, delete and undelete, bulk lists, Database methods with partial success and error handling, with stand-ins.
Triggers
- Apex Trigger Basics Learn what Apex triggers are, the trigger syntax, before and after triggers, the seven events, when to use each, and the order of execution, with Java stand-ins.
- Trigger Context Variables Use Trigger.new, Trigger.old, Trigger.newMap, Trigger.oldMap and the isInsert, isBefore and operationType flags to detect what changed in an Apex trigger.
- Bulkification in Triggers Learn to bulkify Apex triggers so they handle 200 records safely: collect Ids, query once, group with maps, update in bulk, with runnable Java stand-ins.
- The Trigger Handler Pattern Organise Apex trigger logic with the handler pattern: a logic-free trigger, a handler class with before and after methods, a base class, recursion control, with stand-ins.
Classes and Testing
- Apex Classes, Interfaces and Access Modifiers Learn how Apex classes, constructors, interfaces, access modifiers and sharing keywords work, with real Apex code and runnable Java stand-ins for the design ideas.
- Apex Inheritance, Virtual Methods and Abstract Classes Learn Apex inheritance: virtual and abstract classes, override, super, polymorphism and when to prefer composition, with real Apex and runnable Java stand-ins.
- Apex Test Classes, Assertions and Code Coverage Write Apex unit tests: @isTest, System.Assert methods, Test.startTest and stopTest, bulk and negative tests, and the 75 percent coverage rule, with a Java test-harness stand-in.
- Apex Test Data Factories, @TestSetup and Mocking Build reusable Apex test data with factories and @TestSetup, and isolate code with the Stub API and interface-based test doubles, shown in Apex and Java stand-ins.
Asynchronous Apex
- Apex Future Methods and Asynchronous Basics Learn asynchronous Apex and @future methods: when to go async, the rules and limits, callouts from triggers, and a runnable Java stand-in of a background job queue.
- Queueable Apex: Chaining, Job Ids and Finalizers Learn Queueable Apex: implement the interface, pass sObjects, chain jobs, track the job Id and use finalizers, with Apex listings and a runnable Java job-chain stand-in.
- Batch Apex: start, execute, finish and Scope Size Learn Batch Apex: the Database.Batchable interface, start, execute and finish, scope size, Database.Stateful, chaining and testing, with a runnable Java chunking stand-in.
- Scheduled Apex and Cron Expressions Learn Scheduled Apex: implement Schedulable, write cron expressions, schedule from code or Setup, launch batches on a timer and test schedules, with a runnable Java cron stand-in.
Lightning Web Components
- Lightning Web Components: Your First Component Learn Lightning Web Components: the bundle files, HTML templates, lwc:if, for:each, public properties with @api and the meta XML, with a runnable JavaScript template stand-in.
- LWC Reactivity, Events and Component Communication Understand LWC reactive properties, event handlers, CustomEvent from child to parent, @api methods and the Lightning Message Service, with runnable JavaScript stand-ins.
- Calling Apex from LWC with @wire and Imperative Calls Learn how a Lightning Web Component calls Apex: @AuraEnabled(cacheable=true), @wire, imperative calls, error handling and refreshApex, with a runnable JavaScript stand-in.
- LWC Lifecycle Hooks and Jest Testing Learn the LWC lifecycle: constructor, connectedCallback, renderedCallback and disconnectedCallback, then test components with Jest, with runnable JavaScript stand-ins.
Integration and Deployment
- Making REST Callouts from Apex and Mocking Them Call external REST APIs from Apex with Http, HttpRequest and Named Credentials, parse JSON, handle errors and test with HttpCalloutMock, plus a runnable Java HTTP stand-in.
- Exposing Apex as a REST Service with @RestResource Build a custom REST endpoint in Apex with @RestResource, @HttpGet, @HttpPost, RestContext, status codes and tests, with a runnable Java router stand-in.
- Deploying Apex and LWC with the Salesforce CLI Learn source-driven Salesforce development: SFDX project layout, scratch orgs, sf project deploy, running Apex tests, package.xml and CI/CD, with a Java deploy-order stand-in.
Projects and Practice
- Project: A Trigger Handler Framework Build a reusable Apex trigger handler framework: a base class, one trigger per object, recursion guard, bypass switch and tests, with a runnable Java dispatcher you can extend.
- Project: A Nightly Data Cleanup Pipeline Build a nightly Apex pipeline: a Schedulable launches a stateful batch that archives stale records, collects failures and chains a queueable summary, with tests and a Java simulation.
- Practice: Governor Limits, Patterns and Interview Questions Practise Apex governor limits, bulkification patterns, order of execution and common interview questions, with exercises and a runnable Java limit-meter stand-in.