String (Introduction Only)
Learning Content
Last updated: July 28, 2026
String Data Type (Introduction Only)
The String data type is used to store textual information in Apex. A String can contain letters, numbers, spaces, symbols, or a combination of all these characters.
Almost every Salesforce application works with text data, such as customer names, email addresses, company names, phone numbers, addresses, product names, and Opportunity descriptions. Because of this, String is one of the most frequently used data types in Apex.
In this lesson, you'll learn the fundamentals of the String data type. Advanced String methods and text manipulation techniques will be covered in a dedicated chapter later in this course.
💡 LearnFrenzy Insight
Think of a name badge at a conference.
It may contain:
- John Smith
- Sales Team
- Employee ID: EMP1024
- London Office
All of this information is text. In Apex, text values are stored using the String data type.
What is a String?
A String is a sequence of characters enclosed in single quotes (' ') in Apex. It can store words, sentences, numbers represented as text, or any combination of characters.
String company = 'LearnFrenzy'; String city = 'London'; String employeeId = 'EMP1024';
Why Use String?
| Reason | Benefit |
|---|---|
| Store Text | Represents names, addresses, descriptions, and other textual information. |
| Readable Data | Makes business information easy to understand. |
| Universal Usage | Used throughout Salesforce objects and custom applications. |
| User Input | Captures values entered by users in forms and records. |
Variable Declaration
String firstName = 'Emma'; String accountName = 'Universal Trading Ltd'; String country = 'United Kingdom';
String Concatenation
Multiple String values can be combined using the + operator.
String firstName = 'Emma'; String lastName = 'Watson'; String fullName = firstName + ' ' + lastName; System.debug(fullName);
Output
Emma Watson
Real Salesforce Business Example
🏢 Business Scenario A company stores customer information in Salesforce.
String customerName = 'James Anderson'; String accountName = 'Global Retail Ltd'; String city = 'Manchester'; System.debug(customerName); System.debug(accountName); System.debug(city);
Output
James Anderson Global Retail Ltd Manchester
These values may later be displayed on Lightning pages, reports, emails, or customer records.
Common Salesforce Use Cases
| Business Requirement | Example |
|---|---|
| Customer Name | 'John Smith' |
| Email Address | 'john@example.com' |
| Company Name | 'LearnFrenzy Pvt Ltd' |
| Phone Number | '+44 7700 900123' |
| Product Name | 'Laptop Pro X' |
| Opportunity Description | 'Annual Software Renewal' |
String vs Other Common Data Types
| Data Type | Stores | Example |
|---|---|---|
| String | Text | 'Salesforce' |
| Integer | Whole Numbers | 100 |
| Decimal | Financial Values | 2500.75 |
| Boolean | true / false | true |
| Date | Calendar Date | 2026-07-25 |
Did You Know?
📌 Interesting Fact
Unlike some programming languages such as Java or C++, Apex does not have a separate char data type.
Even a single character is stored as a String.
String grade = 'A'; String gender = 'M';
How Salesforce Stores String Values
Developer Writes
String company = 'LearnFrenzy';
│
▼
Compiler Checks
✔ String Type
✔ Variable Name
✔ Text Value
│
▼
Memory Allocated
│
▼
Characters Stored
L e a r n F r e n z y
│
▼
Available for Display and Processing
🔍 Behind the Scenes
User Enters Name
│
▼
Stored as String
│
▼
Displayed on Record Page
│
▼
Used in Reports
│
▼
Shown in Emails & Integrations
✅ Best Practices
- Use meaningful variable names such as
customerName,accountName, oremailAddress. - Store only textual information in String variables.
- Use concatenation to build readable messages when needed.
- Keep user-facing text clear and descriptive.
⚠️ Common Mistakes
- Using String to store values that should be Integer, Decimal, or Date.
- Assuming Apex has a separate
chardata type. - Using unclear variable names such as
str1ortextValuewhen a more descriptive name is possible. - Adding unnecessary spaces when concatenating text.
🎯 Interview Tip
Question: Does Apex support a separate char data type?
Answer: No. Apex does not provide a separate char type. A single character, such as 'A' or 'M', is stored using the String data type.
📌 Quick Revision
- ✔ String stores textual information.
- ✔ String values are enclosed in single quotes.
- ✔ Use the
+operator to concatenate text. - ✔ Commonly used for names, emails, company names, addresses, and descriptions.
- ✔ Apex does not have a separate
chardata type. - ✔ Advanced String methods will be covered in a later chapter.
➡ Next Lesson
In the next lesson, you'll explore the Date data type, learn how Apex represents calendar dates, create Date values, and perform common date operations used in Salesforce business applications.
Practice What You've Learned
Test your understanding with these practice exercises