Write Apex: Apex practice drills
Variables, numbers, text, dates, if and switch, loops, Lists, Sets and Maps. Your Apex foundation.
26 drills · Beginner · Free to run
- Comments that survive review (Beginner, 5 min)
Explain why an Account field is set, switch off scratch logs, and keep the useful log running. - Hello, ApexSensei (Beginner, 5 min)
Run your first Apex statement in Salesforce and read its labeled debug output. - Quick win: double a number (Beginner, 5 min)
Write a one-line method that returns a number times two. Your first method that returns a value. - Quick win: greet by name (Beginner, 5 min)
Join text and a variable with + to build a greeting for any name. - Quick win: is it positive? (Beginner, 5 min)
Return true or false from a comparison. Meet the Boolean type and see what happens with null. - Quick win: make initials (Beginner, 5 min)
Take the first letter of two names, make them capitals and join them. - Quick win: pick the larger number (Beginner, 5 min)
Return the bigger of two numbers. Your first if. - Quick win: shout it (Beginner, 5 min)
Turn text into capitals and add an exclamation mark. - Quick win: join a full name (Beginner, 5 min)
Put a first and last name together with one space between them. - Quick win: is the name blank? (Beginner, 5 min)
Use String.isBlank to treat null, empty text and spaces the same way. - Integer division and Math.mod (Beginner, 10 min)
Count full seat packs with integer division and leftover seats with Math.mod for two order sizes. - Money is a Decimal (Beginner, 10 min)
Round Opportunity tax and total with HALF_UP, and see how plain setScale(2) rounds a tie differently. - True, false, and null (Beginner, 12 min)
Give a missing Lead score a default before doing math, then decide if the Lead is hot in three cases. - Clean a Contact name (Beginner, 12 min)
Trim spaces, fix capital letters, and drop a temporary suffix from imported Contact names. - Parse an email (Beginner, 12 min)
Split Contact emails at the @ into mailbox and domain, and handle an email with no @ safely. - Split and join text (Beginner, 12 min)
Split a multi-select picklist value into a List, add a value, join it for display, and split on dots safely. - Working with dates (Beginner, 10 min)
Build Dates, cross a year end, add a month to Jan 31, and count the days between two dates. - Score bands with else if (Beginner, 12 min)
Write a method that sorts a Lead score into Hot, Warm, Cold or Unscored with if / else if / else. - Switch on Case status (Beginner, 10 min)
Pick an action for Case statuses with switch on, a when else default, and a status typed in lowercase. - For loop: number invoices (Beginner, 10 min)
Number three invoices with a for loop, count the passes, and run the loop again with zero invoices. - For-each over Accounts (Beginner, 12 min)
Loop over in-memory Accounts with for-each, count them, and handle an empty List and a null List safely. - While a queue has work (Beginner, 12 min)
Work through an in-memory queue from the front with a while loop until it is empty, and show an empty queue does no work. - Lists of Opportunities (Beginner, 15 min)
Add, read and change in-memory Opportunities in a List, and read items only at safe positions. - Maps: Id to Account (Beginner, 15 min)
Build an Id-to-Account Map from a List, look up known and missing keys, and loop over every key. - Remove duplicate emails with a Set (Beginner, 12 min)
Write a method that counts different emails with a Set<String>, ignoring letter case and skipping empty entries. - Count Leads by Rating with a Map (Beginner, 15 min)
Write a method that counts Leads per Rating in a Map<String, Integer>, then loop over its keys to print each count.