Hello friends, welcome to sfdc Amplified.
This article will cover:
- What is a variable?
- What is a datatype?
- Primitive data types
These are the data types which are predefined by the Apex. Salesforce supports the following Apex data types :
- Primitive data types
- Collections
- sObjects
- Enums
For the scope of this article we will learn primitive data type.
What is a Variable?
It is a place to store information.Variables can be thought of as ‘containers’ for data. Each variable has to have a unique name, so that you can refer back to it in the program.
What is datatype?
Unlike humans, a computer does not understand difference between “1674” and “sfdcamplified.” When creating a variable, we also need to declare the data type it contains. This is because the program will use different types of data in different ways.
There are five basic type of variables. Basically, it gives answer to what kind of information are we going to store.
So lets begin understanding datatypes.
String
- String is always surround with single quote
- Choose most appropriate data type. You cannot add two numbers if data type are string.
String sfdcname = 'SfdcAmplified';
Integer
It is a number without any decimal points. Do not use single quote with integer
Integer strairs = 10; Integer sum = 2+ 5;
Decimal
You can store number with decimal points
Decimal prob = 0.67;
Note: When in confusion then use decimal to avoid data loss
Date
A value that indicates a particular day.
Date currentDate = Date.Today();
DateTime
A value that indicates a particular day and time
DateTime currentTime = DateTime.now();
Boolean
It gives true or false value
Boolean isClosed = True
Note: Boolean do not have quotes
How to create variable in apex
- Choose Datatype
- Choose variableName
String myName = 'Smriti';
I hope you enjoyed this article. For more of these articles stay tuned!
Get latest updates
If you like the Video then subscribe to Youtube Channel
If you like the Article then subscribe to the Blog
Together we can learn faster
You can join the Whatsapp group
You can join Facebook group
You can join Twitter
You can join Instagram