In this blog post, we will cover some basics related to apex programming. We will learn about datatypes, Variables and constants.
Table of Contents
ToggleWhat is Apex class?
A class is a template or blueprint from which objects are created. An object is an instance of a class.
Let’s talk in detail about this class. Think of a class as a blueprint/design for a house, in the blueprint you define your bedrooms, bathrooms, layout of the house but nothing have been constructed yet. +Similarly Class is just a blueprint and just like you use the blueprint to construct houses, similarly we use class to create objects. Every class has three parts: Attributes, Methods and Constructors.
How to create a class in Apex?
public class Employee { //define attributes //define methods //define constructors }
Data Types and Variables:
Variables are typically used to store information. Every variable has a data type which tells us about the type of data we will store in the variable.
Below is the list of data types in Apex:
Primitive data types (Integer,String, Boolean,…etc)
Enum (an enumerated list)
sObjects (sObject, like Account, contact, opportunity or custom object)
Learn more about datatypes here
In order to use a variable in salesforce, we have to first declare the variable.
How to declare a variable in salesforce?
Integer a; //declaring the variable and its type a=25; //intializing the variable with value of 25
You can declare and initialize the variable in the same line as shown below:
integer a=25;