Data Types, Class, Access Modifiers in Salesforce

on

|

views

and

comments

Table of Contents

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
  • 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:

  1. 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.
  2. 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.
  3. 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.
    1. Class A (Parent)
      1. Protected Variables
    2. Class B (Child ) extend Class A (Variable & Methods)
      1. Access Protected Variables
  4. Global
    1. Managed Package ( Application ) ~= Applications in Google/Apple Store
      1. Class
        1. Variable
        2. Method

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

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to Utilize Salesforce CLI sf (v2)

The Salesforce CLI is not just a tool; it’s the cornerstone of development on the Salesforce Platform. It’s your go-to for building, testing, deploying, and more. As one of the most important development tools in our ecosystem

Save the day of a Developer with Apex Log Analyzer

Table of Contents What is Apex Log Analyzer? Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your...

Salesforce PodCast

Introduction Hey Everyone, Welcome to my podcast, the first-ever podcast in India for Salesforce professionals. Achievement We are happy to announce that we have been selected as Top...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential