Salesforce Notes.pptx
Salesforce Notes.pptx
ARCHITECTURE
CORE ARCHITECTURE OF SALESFORCE?
▪ App: All metadata elements such as objects, Visualforce pages, classes, etc. are independent of an app. An app
simply helps you cluster things visually. However, internal metadata has nothing to do with the app, but you’ll be
able to have a similar tab, VF Page, etc. in multiple apps.
▪ Instance: An instance of Salesforce is the particular configuration that you see when you log in to Salesforce. A
Salesforce instance basically indicates server details for a particular Salesforce organization on which it lives. It is
possible for many Salesforce instances to live on one server. While an instance is created based on the location of
a user, it will be changed based on the region from where the user logs in.
▪ Superpod: Superpod is the arrangement of frameworks and stack balancers, including outbound intermediary
servers, system and capacity foundations, mail servers, SAN texture, and various other frameworks supporting
different instances.
▪ Org (organization): It is a single consumer of the Salesforce application. An org is incredibly adjustable and has
very clear security and sharing settings.
▪ Sandbox: Whenever a sandbox is created, Salesforce copies the metadata from your production org to the
sandbox org. By doing so, you can create multiple copies of your production org in separate environments.
MULTI-TENANT ARCHITECTURE
▪ Multi-tenant architecture: Multitenancy is when
several different cloud customers are accessing the
same computing resources, such as when several
different companies are storing data on the same
physical server. It isolates and concurrently
supports the varying requirements of many
tenants.
▪ Advantage of multi-tenant architecture:
▪ It is cost-effective as the application is shared by
multiple clients.
▪ The development and maintenance costs of an
application is low.
▪ Application and Server Patching in one-go
▪ Efficient
METADATA & API
METADATA
▪ The metadata means data about the data. Salesforce stores the metadata in
the shared database along with the data. It means it stores the data as well
as what data does.
▪ The tenant-specific data ensures that the common data is only shared with
one tenant, not with another tenant or group (as shown in figure). This
ensures the security of the data even in the shared database.
API
▪ The API provides a simple but powerful, and open way to programmatically
access the data and any app running on the salesforce platform.
▪ These APIs helps the developers to access apps from any location, using any
programming language that supports Web services, like Java, PHP, C#,
or .NET.
APEX
WHAT IS APEX?
▪ Apex is a strongly typed, object-oriented programming language that allows developers to execute the flow and transaction
control statements on the Force.com platform server in conjunction with calls to the Force.com API.
▪ Apex has a Java-like syntax and acts like database stored procedures.
▪ It enables the developers to add business logic to most system events, including button clicks, related record updates, and
Visualforce pages.
▪ Apex code can be initiated by
▪ Web service requests
▪ Triggers on objects.
▪ Apex is included in Performance Edition, Unlimited Edition, Enterprise Edition, and Developer Edition.
FEATURES OF APEX
▪ Integrated
Apex has built in support for DML operations like INSERT, UPDATE, DELETE and also DML Exception handling.
It has support for inline SOQL and SOSL query handling which returns the set of sObject records.
▪ Strongly Typed
Apex is a strongly typed language. It uses direct reference to schema objects like sObject and any invalid reference quickly fails if it is
deleted or if is of wrong data type.
▪ Multitenant Environment
Apex runs in a multitenant environment. Consequently, the Apex runtime engine is designed to guard closely against runaway code,
preventing it from monopolizing shared resources.
Any code that violates limits fails with easy-to-understand error messages.
▪ Easy Testing
Apex provides built-in support for unit test creation and execution, including test results that indicate how much code is covered, and
which parts of your code can be more efficient.
APEX DOESN’T SUPPORT
▪ You cannot change the standard SFDC provided functionality and also it is not possible to prevent the standard functionality
execution.
▪ Creating multiple threads is also not possible as we can do it in other languages.
WHEN TO CHOSE APEX
▪ Create Web services with integrating other systems.
▪ Perform complex validation over multiple objects at the same time and also custom validation implementation.
▪ Create complex business processes that are not supported by existing workflow functionality or flows.
▪ Create custom transactional logic (logic that occurs over the entire transaction, not just with a single record or object) like
using the Database methods for updating the records.
▪ Perform some logic when a record is modified or modify the related object's record when there is some event which has
caused the trigger to fire.
Working Structure of Apex
ASYNCHRONOUS APEX
▪ Queues
▪ @future
▪ Continuations (UI)
ASYNCHRONOUS VS SYNCHRONOUS
Asynchronous Synchronous
Actions that will not block the transaction or
Quick and Immediate actions
Process
Duration is not priority Transactions are immediate and serial
Synchronous Programming
Synchronous programming in Apex executes tasks sequentially, one after the other, in the order they are
called. While simpler to understand, synchronous programming can lead to performance issues if tasks
take a long time to complete, as it blocks the main thread until execution finishes.
APEX SYNTAX
▪ Variable Declaration
Variables to be declared with data type in Apex. Example: lstAcc is declared with data type as List of Accounts.
▪ SOQL Query
This will be used to fetch the data from Salesforce database. The query shown in screenshot is fetching data from Account object.
▪ Loop Statement
This loop statement is used for iterating over a list or iterating over a piece of code for a specified number of times.
▪ DML Statement
Performs the records insert, update, delete operation on the records in database. Example, the code given below helps in updating Accounts with new field value.
COLLECETIONS IN APEX
▪ List - List can contain any number of records of primitive, collections, sObjects, user defined
and built in Apex type. Always starts with 0. This is synonymous of Array in Java
Example:
List<string> ListOfCities = new List<string>(); System.debug('Value Of
ListOfCities'+ListOfCities);
▪ Set
▪ Map
LOOP IN APEX
1 for loop This loop performs a set of statements for each item in a set of records.
2 SOQL for loop Execute a sequence of statements directly over the returned set o SOQL query.
while loop Repeats a statement or group of statements while a given condition is true. It tests the condition before
4
executing the loop body.
5 do...while loop Like a while statement, except that it tests the condition at the end of the loop body.
TRIGGERS
WHAT IS APEX TRIGGERS?
Triggers in Salesforce are programmatic event handler that executes custom actions before or after specific
operations on Salesforce records. These operations can include the creation, update, or deletion of a record.
Triggers, written in Apex (Salesforce’s proprietary programming language), provide a powerful way to automate
complex business processes.
The triggers are apex codes that execute before or after specific operations, include;
• insert
• update
• delete
• merge
• upsert
• Undelete
• Syntax
Trigger <trigger name> on <object name> (trigger Events) { }
The primary use of triggers in Salesforce is to automate and manage complex business operations that can’t be
handled by Salesforce’s built-in point-and-click tools. Triggers can validate or modify field values before they’re
saved to the database, create or modify related records, perform complex calculations, enforce custom business
logic, or integrate with external systems.
HOW TO CREATE AN APEX TRIGGER IN SALESFORCE?
▪ Trigger to be created in the sandbox or a developer edition org.
No matter what apex code you run there, it doesn’t affect your
live Salesforce database. Sandbox is very convenient for
developers.
▪ Governor Limits: Salesforce enforces various limits on the number of database operations, the amount of CPU
time, and the memory capacity that triggers can use.
▪ Order of Execution: The order in which triggers are executed can’t be explicitly controlled.
▪ Testing and Deployment: Triggers must have at least 75% test coverage in order to be deployed to a production
environment.
▪ Recursive Triggers: Avoiding recursive triggers can be complex. If the same trigger is fired continuously, you may
run into infinite loops.
▪ Complexity: Triggers can become complex, especially as more business logic is added. This can lead to
difficult-to-maintain code.
INTEGRATIONS
IN SALESFORCE
INTEGRATION PATTERNS IN SALESFORCE
Salesforce can’t be a source of everything. It can be CRM or any Custom application. However, SAP can own Order
Management or Inventory, an External system for sending emails, Other System for Payment, External Fleet Management, And
possibilities are high that Salesforce would need to exchange data with these systems.
FACTORS AFFECTING PATTERN
▪ Maintain same transaction : Does Salesforce need to perform anything on response ?
▪ Synchronous vs Asynchronous : Is it business critical & response needs to be processed in real time or near real time ?
▪ Contract first integration possibility : Can remote system follow Salesforce Contract ?
▪ Using ETL Tool : This tool connects to systems, extract data, transform in require target format and uploads using Bulk API
or SOAP API
▪ Manual Remote Calls : Salesforce or external system can call each other every time data is changed. However, it would
cause huge ongoing traffic and should be avoided if possible
SALESFORCE INTEGRATION PATTERNS & BEST PRACTICES
4. Remote Call-In
Data stored in Lightning Platform is created, retrieved, updated, or deleted by a remote system.
▪ SOAP & Rest API