Salesforce Free Developer >

Chapter 2 - Apex Basics >

Apex Variables and Apex Literals

Apex Variables and Apex Literals

Apex Variables

A variable is a named value holder in memory. In Apex, local variables are declared with Java-like syntax.

The name we choose for a variable is called an identifier. Identifiers can be of any length but they must begin with an alphabet. The rest of the identifiers can include digits also.

  • Operators and spaces are not allowed.
  • We can’t use any of the apex reserved keywords when naming variables, methods or classes.
  • Keywords are the words that are essential for the Apex language.
Integer i_a; 🗸 Integer i 2;   ☓
Integer _ia; ☓ Integer i$2;   ☓
Integer ia_; ☓ Integer $i2;   ☓
Integer i2;  🗸 Integer $_i_2; ☓

Apex Constants

Apex Constants are the variables whose values don’t change after being initialized once.

Constants can be defined using the final keyword. Constants can be assigned almost once either in the declaration itself or with a static initialization method if the constant is defined in a class.

final integer a =5;

Note: We cannot use the final keyword in the declaration of a class or a method because in apex classes and methods are by-default final and cannot be overridden or inherited without using the virtual keyword.

Apex Literals

Integer i = 123;

String str = ‘abc’;

Expression:

An Expression is a combination made up of variables, operators and method invocation that evaluates to a single value.

Datatypes:

Apex is a strongly typed language i.e we must declare the datatype of a variable when we first refer to it. All apex variables are initialized to null by default.

Expression:

An Expression is a combination made up of variables, operators and method invocation that evaluates to a single value.

Datatypes:

Apex is a strongly typed language i.e we must declare the datatype of a variable when we first refer to it. All apex variables are initialized to null by default.





 

 

Cyntexa CTA

Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners. But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

Your email address will not be published. Required fields are marked *