Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 44

SALESFORCE

DEVELOPMENT

-Shhaillaja Ghugarre
Introduction to Apex

-Components of Apex
-How does Apex works?
Object-Oriented
Programming Language
(OOPS)
Encapsulation:
Encapsulation is variables and methods together into a single unit and preventing them from being accessed by other classes.

Data Hiding Information Security Code Maintainability

The power of encapsulation Encapsulation safeguards Encapsulation enhances code


in protecting internal data and sensitive information and maintainability by isolating
methods from external prevents unauthorized access. changes within classes
interference.
Inheritance:
When one object acquires all the properties and behaviors of
parent objects i.e. known as inheritance. It’s creating a parent-
child relationship between two classes. It provides code
reusability.

Polymorphism:
Polymorphism refers to the ability of a variable, object, or
function to take on multiple forms. We use method overloading
and method overriding to achieve polymorphism.
Polymorphism:
1 Compile-Time Polymorphism

Run-Time Polymorphism 2
Abstraction

1 The Essence of Abstraction

Abstraction allows the creation of simplified models that capture the


features of complex systems.

2 Usability and Maintainability

Abstraction improves the usability and maintainability of code by providing clear


interfaces.
Data Types in Salesforce
1 Integer 2 Double
Fields of this type contain The double data type is basically
numbers with no fraction portion
a precision sort of data type

3 String 4 Decimal
It is a sequence of characters, either as
It provides the greatest number of
a literal constant or as some kind of
significant digits for a number
variable.

5 Date and Time


6 Boolean
Stores dates, times, or both, for Stores true/false values, useful for
tracking events or scheduling tasks. conditional logic or flagging fields.

7 Picklist 8 Long
Long data types are whole numbers,
Provides a predefined list of values both positive and negative, that have
many place values.
from which users can select.
Currency
Email Phone
Handles numerical values with
Stores email addresses and Stores phone numbers with
currency symbols, precision,
includes validation and country codes, validation, and
and conversion rates.
formatting options. formatting options.

URL Address

Stores website addresses and Includes fields for complete


ensures valid URLs are address information, such as
entered. street, city, state, and postal
code.
Data Members and
Class Methods
In object-oriented programming (OOP), data members and class methods are
essential components. Within a class, data members represent the state of an
object, while class methods interact with these data members in various ways.
Data Members
Definition 📖
Data members are variables declared within a class that store data
related to an object's state.

Class Methods
Defination

Class methods are functions declared within a class that


operate on class-level data and aren't tied to a specific object
instance.
Access Modifier
Access modifiers control the visibility and accessibility of variables, methods,
and classes.

Types Of Access Modifier:


Public Access Modifier
Private Access Modifier
Protected Access Modifier
Global Access Modifier
Public Access Modifier
The public access modifier allows unrestricted access to variables, methods, and classes. It
is commonly used for components that need to be accessed from other classes or packages.

Private Access Modifier


The private access modifier restricts access to only the defining class. It ensures
encapsulation and data integrity.

Protected Access Modifier


The protected access modifier allows access within the defining class and its subclasses. It
enables controlled sharing of data between related classes. We use protected when you
want to expose certain members to subclasses without making them completely public.

Global Access Modifier


The global access modifier makes methods and variables available across different
namespaces. It is commonly used in managed packages to allow external
components to access specific functionalities.
Class Variables
Class-level variables are variables that are declared in a class, but
outside of a method. These variables are accessible to all the methods of
the class and are shared by all instances of the class.

Why use class variables?


They allow data to be shared between multiple methods, and by all
instances of the class, making it a powerful tool for organizing and
simplifying complex code.

Constructor
Constructor is a special member of a class used to initialize the
data members of class
Apex Methods
Apex methods provide a bridge between the front-end
Visualforce Pages and the back-end Apex code, allowing
seamless communication between them.
Benefits

1 Enhanced 2 Improved User 3 Code Reusability


Functionality Experience
Apex methods enable By leveraging Apex Apex methods can be
complex calculations, methods, you can reused across multiple
data manipulation, and create interactive Visualforce Pages,
integration with elements and real-time reducing development
external systems. updates on the time and increasing
Visualforce Pages. maintainability.
Defining Apex Methods

Method Signature

Define the method name, return type, and parameters in


the Apex class.
Passing Parameters

Simple Parameters Complex Parameters

Pass primitive data types or custom object Pass lists, sets, or maps to handle multiple
instances as parameters. values or complex data structures.
About Arrays
An array is a data structure that stores a fixed-size sequential collection of elements of the same type.

Common Use Cases

Data Analysis Customer Support Inventory Management


Collections
What is a collection?

A collection is a container that can hold multiple values of different or same types.

Types of collections

1. List: A list is a sequential collection of elements. It allows duplicates.


e.g List<Account> acclist = new List<account>();

2. Set A set is another collection type. Unlike List set is unordered as well as doesn’t allow duplicates.
e.g Set<Id>conid =new Eet<Id>();

3. Map : Maps are collections types which supports key-value pairs.


e.g Map<Id,Account>idToAccountMap = new Map<Id,Account>();
Operations for Working with Collections

List Set Map


• Sorting • Duplicate elimination • Key-value mappings
• Add/Remove elements • Membership checking • Retrieving values
• Iterating • Set operations (union, • Updating values
intersection)
What is DML?
DML, or Data Manipulation Language, is a set of operations that allow you to
insert, update, delete, or upsert records in Salesforce databases.
DML operations are essential for managing and maintaining data integrity in
Salesforce. They enable us to make changes, create new records, and remove
unnecessary data.
Types of DML operations
1 Insert

Create new records in the Salesforce database.

2 Update 🔄

Modify existing records in the Salesforce database.

3 Delete

Remove records from the Salesforce database.

4 Upsert

Insert or update records in the Salesforce database based on provided


parameters.
Examples of DML operations in Salesforce

1 Create New Contact

Insert a new contact with all the

Update Lead Status required information.


2
Change the status of a lead based on
recent interaction. 3 Delete Opportunity

Remove an opportunity that is no


longer valid.
Batch Apex
Batch Apex in Salesforce allows you to process large data sets in smaller,
manageable chunks for efficient processing and improved performance.

Types Of Batch Apex


1. Start Method

2. Execute method

3. Finish method
Start method:
This method will be called at the starting of the Batch Job and collects the data on which
the Batch job will be operating.
Use the Database.QueryLocator object when you are using a simple query to generate the scope
of objects used in the batch job.
Execute method
where, list<sObject> is returned by the Database.QueryLocator method.
This method gets called after the Start method and does all the processing
required for Batch Job.
Finish method
This method gets called at the end and you can do some finishing activities
like sending an email with information about the batch job records processed
and status.

After finish method executes, the batch job status is updated, and any
associated asynchronous actions, like email notifications, can be
triggered.
Triggers in Salesforce
Triggers are powerful mechanisms that enable developers to
automate business processes, enforce custom logic, and respond to
data changes.

Trigger is a piece of Apex code that executes before or after specific


data manipulation events. It is essentially a custom code that listens
to changes in your Salesforce organization and takes specific actions
based on those changes.
How Triggers work
1 Event Occurs

When a specific event, such as

Trigger Executes record creation or update, occurs in


2
Salesforce.
The trigger code runs, allowing you
to perform custom logic, validations,
3 Database Commit
or updates.
Once the trigger and associated
actions complete successfully, the
changes are committed to the
database.
Trigger context variables
Trigger.new Trigger.old

The new version of the records being The old version of the records prior to the
inserted, updated, or deleted in the trigger. trigger operation.

Trigger.newMap Trigger.oldMap

A map of record IDs to the new version of A map of record IDs to the old version of
the records. the records.
Trigger events

Before Events After Events Batch Events

Execute before the record is Execute after the record is Execute on multiple records
saved to the database. saved to the database. simultaneously.
Test Classes
Test classes are essential in Salesforce to verify the functionality and integrity
of Apex classes, triggers, and batch processes.

Test classes are specially designed code that validates Salesforce


functionalities, ensuring expected results and preventing bugs.
Apex Class Test Classes

Apex class test classes validate the behavior of your custom Apex classes, ensuring their
correctness in various scenarios.
Apex Trigger Test Classes
Testing Apex triggers is an important aspect of ensuring the quality and reliability of your
Salesforce application.
Batch Apex Test Classes
Test classes for batch apex help optimize processing and ensure high-performance data retrieval, analysis, and updates.
Apex batch jobs are a powerful tool in Salesforce that allow you to process large amounts of data in an efficient and scalable way.
Apex Component
An Apex component in Salesforce is a reusable and customizable building block
that allows developers to create powerful and dynamic web pages.

An Apex component is a modular, self-contained unit of functionality that can be


easily integrated into any Salesforce application. It encapsulates both visual and
logical components, making it highly reusable and configurable.
Apex Input Component
An Apex input component allows users to input data into a Salesforce application. It supports various input types,
such as text fields, checkboxes, radio buttons, and dropdown menus, providing a seamless user experience.
Apex Output Component
An Apex output component displays dynamically generated content in a
Salesforce application. It can include text, images, tables, or any other type of
visual representation based on the data retrieved from the database.
Lightning Components

Lightning Components are reusable building blocks for developing dynamic and
interactive user interfaces. Lightning component is a user interface (UI)
framework that is used to create applications for desktop and mobile
technologies.

Standard: It is out-of-the-box components provided by Salesforce.


Custom: These components are created by development team.
Managed: These components are downloaded from the AppExchange, in the
exact same way you would an app.
Lightning Events

Salesforce Lightning is a component


based framework for the application
development.Component is the core part of
the lightning framework. The communication
between components are handled by
events.

There are two types for events:


-Component Event
-Application Event
Component Event:

Component Event can only be handled by


components and the communication will be simple
between components. Salesforce
recommends using Component events instead of
application events. The component events can
only be registered in child component and handled
by parent component.
Application Event:

Application Event helps in passing values


between two independent events (without parent
child relationship). It means that in case of
Application Events, any component with the
handler statement defined for the event can
receive the fired event.
THANK YOU !

You might also like