Notes
String: A String is a sequence of characters enclosed in single quotes. It's commonly used to store text values.
For example:
String name = 'John Smith';
Integer: n Integer is a whole number without any decimal point. It's commonly used to store numeric values.
For example:
Integer age = 30;
Decimal: A Decimal is a number that contains a decimal point. It's commonly used to store numeric values with high precision.
For example:
Decimal price = 3.99;
Double: A Double is a floating-point number that has greater precision than a Float. It's commonly used to store numeric values with very high precision.
For example:
Double pi = 3.14159265370679;
Boolean: A Boolean is a data type that can only have one of two possible values: True or False. It's commonly used to represent logical values.
For example:
Boolean isHappy = true;
Long: A Long is a whole number that has a greater range than an Integer. It's commonly used to store large numeric values.
For example:
Long population = 7800000000;
Object: An Object is a data type that can be used to represent any type of data. It's commonly used to store complex data structures.
For example:
Account myAccount = new Account();
List: A List is a data structure that can store multiple values of the same data type in a single variable. It's commonly used to store collections of data.
For example:
List<String> names = new List<String>{'John', 'Jane', 'Mike'};
Set: A Set is a data structure that can store multiple values of the same data type in a single variable, but each value must be unique. It's commonly used to store collections of unique data.
For example:
Set<String> fruits = new Set<String>{'apple', 'banana', 'orange'};
Array: An Array is a data structure that can store multiple values of the same data type in a single variable. It's similar to a List, but it's fixed in size and has a different syntax.
For example:
Integer[] numbers = new Integer[]{1, 2, 3, 4, 5};
Map: A Map is a data structure that can store key-value pairs of any data type. It's commonly used to store collections of data that can be accessed by a unique key.
For example:
String name = 'John Smith';
More About Object: In Apex, the Object data type is used to represent any data type, including built-in and custom data types. It's a very flexible data type that can hold any type of data, and can be used when the data type is not known in advance or when dealing with complex data structures.
Here's an example of using the Object data type to hold a String value and an Account object:
Object myObj;
myObj = 'Hello, world!';
System.debug('myObj: ' + myObj); // Output: myObj: Hello, world!
myObj = new Account(Name='Acme Inc.');
System.debug('myObj: ' + myObj); // Output: myObj: Account:{Name=Acme Inc.}