Mytutorialrack

In this tutorial, we will learn about apex programming. We will learn about classes, Datatypes, Variables and constants.

What is Apex class?

A class is a template through which we create objects. A class contains group of variables and methods. We can create object using the class.

Data types and variables- Basics of Coding

In any programming language, we need to store data and data can be in the form of numbers, string etc. In order to store data we need variables. Each variable should have a data type. Data types are used to define variables and methods in classes. In apex, all variables and expressions should have data types.
Below are some of the Apex Data types

  • Primitive data types( Integer, Boolean, String … etc)
  • Enum (an enumerated list)
  • sObjects (sObjects, or Account, Contact, object__c)
  • Collection(list,Set, Map)
  • Null (for the null constant. which can be assigned to any variable)
  • An Object created by the user: Classes created by the user

Primitive Data Types
Enumerated List or Enum data type: Enumerated list (or Enum) is an abstract data type that stores one value of a finite set of specified identifiers.
If we wanted a variable to store values like {Winter, Summer, Spring } then in this case we will create Enum.
To define Enum, we use Enum Keyword in the variable declaration and then define the list of values.

sObjects

Collection Data types: There are three main types of collections available in Apex.
List: An ordered collection of elements. In the list, each element has an index number which starts from 0. Duplicate values are allowed in the case of List.
Set: An unordered collection of unique primitives. Set does not include duplicate elements.
Map: A collection of key-value pair.

Share:

Recent Posts