Salesforce, the world’s #1 CRM provider, provides a wide variety of tools to help organizations deal with large volumes of data sets. The Salesforce data model is designed to understand the relationship between different objects.
A data model is defined as the architectural structured way of storing and customizing data in an application. The Salesforce platform provides a standard model that allows the user to customize the data models for custom functionality.
Apex in Salesforce is an object-oriented programming language that enables the user to develop custom business logic on the platform by writing Apex triggers, custom VisualForce controllers and extensions, anonymous Apex codes, etc. It is compiled, stored, and run entirely on the Force.com platform.
Every variable in Apex must be declared with the specific data type such as sObject, primitive, or enum. Data types are defined as the data storage format that a variable can store to perform a specific operation.
Apex in Salesforce supports the following data types:
- Primitive (Integer, Double, Long, Date, Datetime, String, ID, or Boolean)
- Collections (Lists, Sets, and Maps)
- Classes, Objects, and Interfaces
Primitive Data Types
Primitive data types include Integer, Double, Long, Date, Datetime, String, ID, Boolean, etc.
All primitive data types are passed by value, not by reference.
All Apex variables, including class member variables, are initialized to null. Before using the data variables, the users must ensure that they initialize variables to appropriate values.
Integer num = 10;
Boolean check = true;
String name = ‘Test’;
sObject Data Types
A sObject data type can be generic or non-generic. sObject declared with generic type can store any standard or custom object of Salesforce. While the non-generic sObject variable is declared for specific objects.
Generic sObject data types are useful when the users are utilizing SOSL queries that return results from multiple objects.
Sobject s = new Account();
Account a = new Account();
CustomObject__c c = new CustomObject__c();
List – A list is an ordered collection of elements that are identified by their indexes.
- A list contains up to four levels of nested collections. It contains elements of primitive types, sObjects, user-defined objects, Apex objects, or even other collections.
- A list can contain duplicate elements.
Set – A set is an unordered collection of elements that do not contain any duplicates elements. Set elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types. A set is used to store sObject record Ids.
Map – A map is a collection of key-value pairs. Keys and values can be any data type such as primitive types, collections, sObjects, user-defined types, and built-in Apex types. Keys are unique and map elements must be accessed by the key as the order of map elements is not constant.
The map is used to store Salesforce records with their IDs making it easier to iterate over the records.
Enum type defines a fixed set of named constants. An enum is a data type that contains a fixed set of constants.
Variable in Salesforce
Variable is defined as a memory location in the Salesforce platform. A variable is a container that stores a specific piece of data collected from the customer or output from Salesforce. Context Variable is implicit variable, managed, and created to provide developers with the ability to access run time code. It helps the users get information about the Apex Trigger.
Apex in Salesforce utilizes data types, variables, and related language constructs such as enums, constants, expressions, operators, and assignment statements. In Apex, all variables and expressions should initialize a data type, such as sObject, primitive, or enum. Apex uses the same primitive data types as the SOAP API.
Chief Technical Officer (CTO)