ApexSensei

Drills › Write Apex

Build the account label

Write Apex · Beginner · 5 min · Runs in the browser, no org needed · Free

Scenario. A list needs a label built from the company name. Join the parts so a new name still reads correctly.

Join a label and the company name with + instead of typing the whole line.

What you will learn

The + operator joins text. Put the fixed part in quotes and add the variable after it.

String label = 'Account: ' + companyName;

Gotcha. Typing the finished line as one string skips the variable. If the name changes, that line stays wrong.

The task

Build label from the word Account and the company name.

Examples:

  • company name RidgePoint Capital → the label reads Account: RidgePoint Capital
  • company name Northwind → the label reads Account: Northwind

Requirements:

  1. Set label to 'Account: ' plus companyName.
  2. Join the two parts with +.
  3. Keep companyName as the quoted company name.
  4. Do not type the finished label as one piece of text.

Starter code

String companyName = 'RidgePoint Capital';
String label = null;
String city = 'Denver';
Boolean active = true;

When it passes

`label` is `'Account: '` plus `companyName`, and the finished sentence is not typed as one string.

Try this drill free

You write the Apex yourself. ApexSensei runs it and tells you what passed and what did not.

‹ Count open cases · Mark a high score ›