Curriculum
Object Oriented Programming (OOP) is a programming paradigm that organizes software around objects rather than functions and logic. Apex is a fully object-oriented programming language, and understanding OOP concepts is essential for building scalable, reusable, maintainable, and enterprise-grade Salesforce applications.
Object Oriented Programming allows developers to model real-world entities such as Students, Courses, Employees, Customers, Accounts, Opportunities, and Payments as software objects. Through classes, objects, inheritance, polymorphism, abstraction, and encapsulation, developers can create robust applications that are easier to maintain and extend.
Understanding OOP in Apex is one of the most important skills for Salesforce Developers because nearly every Apex application relies on object-oriented principles.
Object Oriented Programming (OOP) is a programming approach based on objects and classes.
OOP helps developers:
Modern Salesforce development heavily relies on OOP concepts.
Without OOP:
OOP provides structure and organization to software development.
Reuse existing functionality.
Simplify updates.
Support business growth.
Protect sensitive data.
Separate responsibilities effectively.
These benefits make OOP essential for Salesforce development.
Object Oriented Programming is based on four major principles.
These principles form the foundation of Apex development.
A Class is a blueprint used to create objects.
Example:
public class Student {
}
The class defines structure and behavior.
An Object is an instance of a class.
Example:
Student student =
new Student();
Objects represent real-world entities.
Class:
Student
Objects:
Rahul
Priya
Amit
The Student class defines common characteristics.
Each object stores individual information.
public class Student {
public String name;
public Integer age;
}
The class contains two properties.
Example:
Student student =
new Student();
student.name = 'Rahul';
student.age = 22;
Object values are assigned dynamically.
System.debug(
student.name
);
Output:
Rahul
Objects store and manage information.
Encapsulation means bundling data and methods together while controlling access to internal details.
Encapsulation protects application data.
Benefits:
Encapsulation improves software quality.
public class Student {
private String name;
}
The variable cannot be accessed directly outside the class.
public class Student {
private String name;
public void setName(
String studentName
){
name = studentName;
}
public String getName(){
return name;
}
}
Getters and Setters provide controlled access.
Student student =
new Student();
student.setName('Rahul');
System.debug(
student.getName()
);
Output:
Rahul
Encapsulation protects object data.
Inheritance allows one class to acquire properties and methods from another class.
Benefits:
Inheritance promotes software reuse.
public class Person {
public String name;
}
This is the parent class.
public class Student
extends Person {
public String course;
}
The Student class inherits the name property.
Student student =
new Student();
student.name = 'Rahul';
student.course =
'Salesforce';
The child class can use parent class properties.
Parent:
Person
Children:
Student
Employee
Customer
All share common characteristics.
Inheritance reduces duplication.
Polymorphism means “many forms.”
It allows the same method to behave differently in different situations.
Benefits:
Polymorphism improves application architecture.
Methods share the same name but have different parameters.
Example:
public class Calculator {
public static Integer add(
Integer a,
Integer b
){
return a + b;
}
public static Decimal add(
Decimal a,
Decimal b
){
return a + b;
}
}
This is compile-time polymorphism.
Calculator.add(10,20);
Calculator.add(
10.5,
20.5
);
Different inputs produce different behavior.
A child class provides its own implementation of a parent method.
Parent:
public virtual class Person {
public virtual void display(){
System.debug('Person');
}
}
Child:
public class Student
extends Person {
public override void display(){
System.debug('Student');
}
}
This is runtime polymorphism.
Student student =
new Student();
student.display();
Output:
Student
The overridden method executes.
Abstraction hides implementation details while exposing essential functionality.
Benefits:
Users focus on what an object does rather than how it works.
Example:
ATM Machine
Users:
Internal processing remains hidden.
This is abstraction.
An Abstract Class cannot be instantiated directly.
Example:
public abstract class Person {
public abstract void display();
}
Abstract classes define common structures.
public class Student
extends Person {
public override void display(){
System.debug(
'Student'
);
}
}
The child class provides implementation.
An Interface defines methods without implementation.
Example:
public interface PaymentProcessor {
void processPayment();
}
Interfaces enforce consistent behavior.
public class OnlinePayment
implements PaymentProcessor {
public void processPayment(){
System.debug(
'Payment Processed'
);
}
}
The implementation provides actual functionality.
Salesforce developers use OOP for:
OOP improves application design.
Example:
public class Utility {
public static Decimal calculateFee(
Integer students,
Decimal fee
){
return students * fee;
}
}
The method can be reused throughout the application.
Example:
Account
Contact
Lead
Opportunity
Salesforce standard objects follow OOP principles.
Custom objects also support object-oriented design.
A software training company manages students.
Class:
public class Student {
public String name;
public String course;
}
Object:
Student student =
new Student();
student.name = 'Rahul';
student.course =
'Salesforce';
This models real-world student information.
Keep classes focused.
Improve readability.
Promote reuse.
Protect data.
Create utility classes.
Improve maintainability.
These practices support scalable applications.
Developers should avoid these issues.
Understanding OOP helps professionals:
OOP is the foundation of Apex programming.
Object Oriented Programming (OOP) is a programming paradigm based on classes and objects. Apex supports the four major OOP principles: Encapsulation, Inheritance, Polymorphism, and Abstraction. These concepts help developers build scalable, maintainable, reusable, and secure Salesforce applications. Mastering OOP is essential for becoming a successful Salesforce Developer and creating enterprise-grade solutions on the Salesforce platform.
Object Oriented Programming is a programming approach based on classes and objects.
Encapsulation, Inheritance, Polymorphism, and Abstraction.
Encapsulation protects data by controlling access through methods.
Inheritance allows one class to acquire properties and methods from another class.
Polymorphism allows methods to behave differently depending on context.
Abstraction hides implementation details while exposing essential functionality.
Looking to learn more technologies and programming skills?
WhatsApp us