This course is currently a work in progress. Please join the waitlist to receive regular updates.

What are variables in apex?

In Apex, a variable is like a container used to store information that can change while the program runs. This information could be a number, text, date, or even a more complex data type like a customer record.

The type of a variable determines the kind of data that can be assigned to it. For example, numbers can be assigned to an Integer variable, while addresses can be assigned to a String variable, and so on.

Following is an example of declaring an integer variable with a default value of 10

Integer
count
=
10
;
Integer count = 10;

Why to use variables

Store Data

Variables act as containers to store information like Name, Age, or Sales.

Name: John, Age: 25, Total Sales: 3000

Make Programs Dynamic

Variables enable programs to adapt based on user input, creating personalized experiences.

Welcome, Sarah! (The name Sarah changes based on the logged-in user

Perform Calculations and Logic

Variables allow you to perform calculations and make decisions using logical conditions.

Total = Price * Quantity (e.g., Total Price: $50)