Day1
If you have missed the previous session here is the link – https://www.pantherschools.com/introduction-to-oops-using-salesforce
Primitive data type in Salesforce
They are simple, basic data types that are built into the Salesforce platform and cannot be broken down into smaller components.
- Integer: A whole number without a decimal point.
- Double: A number with a decimal point or a fractional component.
- Boolean: A data type that can have one of two possible values – true or false.
- Date: A data type that represents a date.
- Time: A data type that represents a specific time.
- DateTime: A data type that represents a specific date and time.
- String: A sequence of characters that can include letters, numbers, and symbols.
- ID: A unique identifier for an object in Salesforce. ( 18, 15 ) 001GHJHGHE87734
- Decimal: A number with a decimal point, with up to 18 digits
Non-primitive data type in Salesforce
The non-primitive data types in Salesforce include:
- Object
- Variables
- Primitive
- Name
- Age
- Non Primitive
- Person Object
- Animal Object
- Primitive
- Variables
- Map
- List
- Set
- Apex Class
- Variables
- Methods
Assignment
Create variables for all the Primitive Data Types and print those with dummy values.
Classes in Salesforce
A class is nothing but it is a collection of objects and carries all the properties of an object.
We can also say that the class is the blueprint for creating the Objects.
A class can contains the followings –
- Classes
- Access Modifiers
- Variable
- Methods
- Constructors
Access Modifiers in Salesforce
Access modifiers in Salesforce are used to define the visibility and accessibility of classes, methods, variables, and other components within an organization.
There are three types of access modifiers in Salesforce:
- Public: Components with the public access modifier are visible and accessible to all classes and triggers in an organization. This means that any class or trigger in the organization can access and use these components.
- Private: Components with the private access modifier are only visible and accessible within the same class in which they are defined. This means that no other class or trigger in the organization can access or use these components.
- Protected: Components with the protected access modifier are visible and accessible within the same class and any subclasses that extend the original class. This means that any class that inherits from the original class can access and use these components.
- Class A (Parent)
- Protected Variables
- Class B (Child ) extend Class A (Variable & Methods)
- Access Protected Variables
- Class A (Parent)
- Global
- Managed Package ( Application ) ~= Applications in Google/Apple Store
- Class
- Variable
- Method
- Class
- Managed Package ( Application ) ~= Applications in Google/Apple Store
Variables(States) in Salesforce
Variables in Salesforce are used to store and manipulate data within Apex code.
<DataType> <VariableName> = <Value>; // Variables Declrations & Value Assigment
Integer myAge = 5;
Decimal mySalary = 76.78K;
String myName = ‘John Doe’;
Hands-On Code
//<access modifier> class <class name>{}
//<access modifier> <access specifier>
public class Animal {
// <access modifier> <DataType> <VariableName> = <Value>;
// <access modifier> <DataType> <VariableName>;
// by default access modifier will be private for any variable
public String name = 'Max'; // String will always be withing Single Quotes
Integer age = 5;
// Instance Variable OR Object Variable
//Multiple-time memory allocation depends upon the of objects
// Class Variable
public static String address = '123 Main Street'; // One time memory allocation
}
// Anynomus Code
//<Data Type> <variable name> = <variable value>;
// Heap Memory
String name = 'John Doe'; // Variable Declaration & Value Assignment
//<Data Type> <variable name>;
Integer age; // Variable Declaration
age = 76;
System.debug(name);
System.debug(age);
//<Class Name> <object Name> = new Constructor();
// new keyword will be used to allocate memory/location/place in Heap Memory
Animal.address = '7677734';
Animal dog = new Animal(); // GHJHGS
System.debug(dog.name); // GHJHGS
System.debug(Animal.address);
Animal cat = new Animal(); // GHJHGS
cat.name = 'Lucy'; //REGF
System.debug(cat.name);
System.debug(Animal.address);
Assignment
Play around with Class & Instance Variable along with Access Modifiers
Full Video
Resources
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_data_types.htm
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_understanding.htm
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_access_modifiers.htm