An apex developer should always make sure that that proper values are assigned to variables. Otherwise such variables when used will throw null pointer exceptions or any unhandled exceptions.

Apex supports the following data types:

  • Primitive (integer, double, long, date, datetime, string, ID, boolean)
  • Collections (lists, sets and maps)
  • sObject
  • Enums (how is this not a collection?)
  • Classes


32 bit number without any decimal point. Range from -2,147,483,648 to 2,147,438,647. I think just remember 2 billion as a rule of thumb.

Integer barrelNumbers = 1000;
system.debug(' value of barrelNumbers variable: '+barrelNumbers);

Here System.debug prints out the current value of the variable barrelNumbers. Is it basically the same as system.out.println() from java?


Boolean is either true, false or (null?).

Boolean shipmentDispatched;
shipmentDispatched = true;
System.debug('Value of shipmentDispatched '+shipmentDispatched);


As the name suggests, this data type is a date. Does not include the time.

//ShipmentDate can be stored when shipment is dispatched.
Date ShipmentDate =;
System.debug('ShipmentDate '+ShipmentDate);


64-bit number without a decimal point. Like an integer but longer.

Long companyRevenue = 21474838973344648L;


We can refer this as any data type which is supported in Apex. For example, Class variable can be object of that class, and the sObject generic type is also an object and similarly specific object type like Account is also an Object.


Consider the following example to understand how the bject variable works.

Account objAccount = new Account (Name = 'Test Chemical');
system.debug('Account value'+objAccount);

Note − You can create an object of predefined class as well, as given below −

//Class Name: MyApexClass
MyApexClass classObj = new MyApexClass();

This is the class object which will be used as class variable.

I do not understand this one. How is it a datatype if it can be any data type? Is being any data type its distinguishing feature, like a catch-all?


Any set of characters within single quotes.

String companyName = 'Abc International';
System.debug('Value companyName variable'+companyName);


This variable is used to store the particular time. This variable should always be declared with the system static method.


A collection of binary data which is stored as an object. Converts attachments in Salesforce into a variable.


This is unique to Salesforce. Something like a table with rows and columns.

Comes in custom and standard types.

Does declaring a new sObject successfully create a new custom object in Salesforce? Or is it more about creating a new record of that sObject type? Or both?

//Declaring an sObject variable of type Account
Account objAccount = new Account();

//Assignment of values to fields of sObjects
objAccount.Name = 'ABC Customer';
objAccount.Description = 'Test Account';
System.debug('objAccount variable value'+objAccount);

//Declaring an sObject for custom object APEX_Invoice_c
APEX_Customer_c objCustomer = new APEX_Customer_c();

//Assigning value to fields
objCustomer.APEX_Customer_Decscription_c = 'Test Customer';
System.debug('value objCustomer'+objCustomer);


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.


You can declare the possible names of Chemical Compound by executing the following code −

//Declaring enum for Chemical Compounds
public enum Compounds {HCL, H2SO4, NACL, HG}
Compounds objC = Compounds.HCL;
System.debug('objC value: '+objC);

I’m not clear on this definition of Enum. My mentor gave this illustration:

It’s a special sort of list, a list of constants, that defines an allowable list of values, like in cards you have suits…

Public enum Cardsuit {CLUBS, DIAMONDS, HEARTS, SPADES}

Cardsuit c = Cardsuit. Hearts

if c == Cardsuit.CLUBS…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s