Welcome to my blog

I have been working with Salesforce for quite a while, so don’t hesitate to contact me if you have any questions or want some advice.

s f

Subscribe
Follow Us
h

APEX DATA TYPES IN SALESFORCE

 . Apex  . APEX DATA TYPES IN SALESFORCE

APEX DATA TYPES IN SALESFORCE

Learn Apex Classes, Objects & Interfaces Data Types in Salesforce

data type constrains the values that an expression, such as a variable or a function, might take. This data type defines the operations that can be done on the data, the meaning of the data, and the way values of that type can be stored.

Apex supports the following data types

  • Primitive (Integer, Double, Long, Date, Datetime, String, ID, or Boolean)
  • Collections (Lists, Sets and Maps)
  • sObject
  • Enums
  • Classes, Objects and Interfaces

1.Primitive data types :

A collection of binary data stored as a single object. You can convert this data type to String or from String using the to String and value Of methods, respectively.

Integer:

A 32-bit number that does not include any decimal point. The value range for this starts from -2,147,483,648 and the maximum value is up to 2,147,483,647.

Double:

A 64-bit number that includes a decimal point. Doubles have a minimum value of -263 and a maximum value of 263-1. For example:

Long:

This is a 64-bit number without a decimal point. This is used when we need a range of values wider than those provided by Integer.

Date:

This variable type indicates a date. This can only store the date and not the time. For saving the date along with time, we will need to store it in variable of DateTime.

Datetime:

A value that indicates a particular day and time, such as a timestamp. Always create datetime values with a system static method. You can add or subtract an Integer or Double value from a Datetime value, returning a Date value. Addition and subtraction of Integer and Double values are the only arithmetic functions that work with Datetime values. You can’t perform arithmetic functions that include two or more Datetime values. Instead, use the Datetime methods.

String:

String is any set of characters within single quotes. It does not have any limit for the number of characters. Here, the heap size will be used to determine the number of characters. This puts a curb on the monopoly of resources by the Apex program and also ensures that it does not get too large.

ID:

Any valid 18-character Lightning Platform record identifier. If you set ID to a 15-character value, Apex converts the value to its 18-character representation. All invalid ID values are rejected with a runtime exception.

Boolean:

This variable can either be true, false or null. Many times, this type of variable can be used as flag in programming to identify if the particular condition is set or not set.

2.sObjects

This is a special data type in Salesforce. It is similar to a table in SQL and contains fields which are similar to columns in SQL. There are two types of sObjects – Standard and Custom.

For example, Account is a standard sObject and any other user-defined object (like Customer object that we created) is a Custom sObject.

3.Enum:

Enum is an abstract data type that stores one value of a finite set of specified identifiers. You can use the keyword Enum to define an Enum. Enum can be used as any other data type in Salesforce.

Resource Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_datatypes_variables_intro.htm

Comments

Post a Comment