All about Salesforce Apex at one place – Coder in Me

Introduction to Apex

Apex is a strongly typed, object-oriented programming language used in Salesforce. According to Salesforce Syntax of Apex  that looks like Java and acts like database stored procedures, Apex enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages. Apex code can be initiated by Web service requests and from triggers on objects.

Datatype of Apex

Primitive Type : Integer , Double, Decimal, Date, Datetime, boolean, String, Id, Time,Long, Object

Integer a=1, it can maximum store  32-bit with no decimal point

Long a=1, it can maximum store  64-bit with no decimal point

Double  d = 2.3 , it can take float or decimal point upto 64 bit

Decimal , it’s float and currency type of salesforce and number type of salesforce will be assigned to this variable.

Date : date dt = Date.newInstance(2019,08,27);

              Date.newInstance(Integer year, Integer month, Integer day) ;

DatetimeDatetime dt = Datetime.newInstance(2019,08,27);   Datetime.newInstance(Integer year, Integer month, Integer day, Integer hour, Integer minute, Integer second)

String :  Any text, text area, id can be stored in string

Boolean , we know to take data from checkbox, or flag handling true or false

Time it will store time only.

What is a Collection?

A Collection is set of any data type ,similar objects or things.
In Salesforce there are 4 types of Collection.but we will discuss here 3 types only.

  1. List: Collection of elements in an ordered way like an array, it can store duplicate elements.
  2. Set: Collection of unique elements in a unordered way.
  3. Map: Map is key – value pairs.

Every data type also represents object in salesforce, we can implements our logic based on their methods.

For example we have multiple methods in string like LEFT, RIGHT, REPLACE,isAlpha, length, remove, reverse,trim, replace, etc.

We have to do some practice on that. like

String str = 'Welcome to Coder In Me';

Now if we want first 4 characters

String str = 'Welcome to Coder In Me';
string frst = str.left(4);

Output will look like this



similarly apex has very good methods to change or use date and datetime methods.


Data types Related methods
String Length()
Replace(‘string a’,’string b’)
Date date dt = date.newInstance(year, month, day)
date dt =date.parse(’12/27/2009′)
dt.addDays(integer value);
dt.addMonths(integer value);
dt.addYears(integer );
Here dt is date variable and Date is used as Date.methodname
Datetime Datetimedt = date.newInstance(year, month, day)
Datetime dt =date.parse(’12/27/2009′)
dt.addDays(integer value);
dt.addMonths(integer value);
dt.addYears(integer );
dt.addHours(integer value);
dt.addMinutes(integer value);
dt.addSeconds(integer );
apex support all the formats click here to check
Here dt is datetime variable

To learn about Collection, Pelase check List and set of collection in Apex and  Learn Map in apex

If, else if

if( Condition ){


}else if ( Other Condition ){





Iteration( Loop )


( initialization; Condition; Increment ){



for(i=0; i<5; i++){

List<String> strList= new List<String>();
For(string str: strList){



A web developer(Front end and Back end), and DBA at Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me

Leave a reply:

Your email address will not be published.