Data Types in Apex
Data Types in Apex
Data type:
Data types are used to define what kind of data a variable can hold.
Integer:A 32-bit number that doesn’t include a decimal point. Integers have a
minimum value of -2,147,483,648 and a maximum value of 2,147,483,647.
Long: A 64-bit number that doesn’t include a decimal point. Longs have a
minimum value of -263 and a maximum value of 263-1. Use this data type when
you need a range of values wider than the range provided by Integer.
Double: A 64-bit number that includes a decimal point. Doubles have a minimum
value of -263 and a maximum value of 263-1.
N.Veera Raghavamma
Decimal:Stores decimal numbers with high precision, commonly used for
currency calculations.
N.Veera Raghavamma
Non-primitive data types:
● Collections
Apex supports three main types of collections for storing multiple values in a single
Variable.
Example:
Set: An unordered collection of unique elements, which can be of any data type.
Example:
Map: A collection of key-value pairs, where each key is unique, and both keys and
values can be any data type.
Example:
parameterized typing:
Example:
N.Veera Raghavamma
● sObject Data Types
sObject: Represents any Salesforce object (both standard and custom objects) in
Apex. All Salesforce records (e.g., Account, Contact) are treated as sObject types.
Example:
The sObject type is the parent class for all standard and custom objects.
○ Account acc;
○ Contact con;
○ Lead lead;
○ Opportunity opp;
Custom sObjects: Objects that you define in Salesforce to store specific business
data.
● Enums:
Enum:
Represents a fixed set of named constants, allowing predefined values. Enums are
commonly used to represent discrete values.
N.Veera Raghavamma
Example:
Example:
this.name = name;
N.Veera Raghavamma
Interfaces: Defines methods without implementation that a class
must implement.
void myMethod();
Definition Basic data types built into More complex data types
the language built from primitive types or
user-defined.
N.Veera Raghavamma