apex programming

In this blog post, we will cover some basics related to apex programming. We will learn about datatypes, Variables and constants.

What 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?

[sourcecode lang=”Java”]
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?

[sourcecode lang=”Java”]
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:
[sourcecode lang=”Java”] integer a=25;[/sourcecode]


Share on facebook
Share on twitter
Share on linkedin
Share on pinterest