Training Day 11 12 Jayaprakash Narayan Thatiparthi Technical

  • Slides: 35
Download presentation
Training Day 11 & 12 Jayaprakash Narayan Thatiparthi Technical Architect

Training Day 11 & 12 Jayaprakash Narayan Thatiparthi Technical Architect

OOPs concepts Introduction to Apex Development Process Data types and Variables Control Structures 2

OOPs concepts Introduction to Apex Development Process Data types and Variables Control Structures 2

OOPs Concepts Overview Of OOPs Concepts 3

OOPs Concepts Overview Of OOPs Concepts 3

OOPs 4

OOPs 4

OOPs – Abstraction 5

OOPs – Abstraction 5

OOPs - Abstraction • A model of a complex system that includes only the

OOPs - Abstraction • A model of a complex system that includes only the details essential to perspective of the viewer of the system. • Only the characteristics of the system that are essential to the problem being studied are modeled; minor or irrelevant details are ignored. • An abstraction is a model of a complex system that includes only the essential details. • Abstractions are the fundamental way that we manage complexity. • Different viewers use different abstractions of a particular system. • Support our quality goals of modifiability and reusability. • Most modifications can be localized to just a few modules. • Supports the creation of generic modules that can be used in other systems. • Major application of Abstraction is basically to deal with the complexity of the system i. e. we use abstractions to simplify our work. • Information hiding and Step wise refinement are synonymously used for abstraction. 6

OOPs - Encapsulation is the process of packaging your program, dividing each of its

OOPs - Encapsulation is the process of packaging your program, dividing each of its classes into two distinct parts: the interface and the implementation by combining the attributes and methods in same entity. Encapsulation is achieved through Classes in Salesforce. 7

OOPs – Encapsulation • One of the primary advantages of using objects is that

OOPs – Encapsulation • One of the primary advantages of using objects is that the object need not reveal all its attributes and behaviors. • In good OO design an object should only reveal the interfaces that other objects must have to interact with it. • Details not pertinent to the use of the object should be hidden from all other objects. • Encapsulation is defined by the fact that objects contain both the attributes and behaviors. • Data Hiding is the major part of Encapsulation 8

OOPs – Composition • Class A contains Class B. • This statement denotes a

OOPs – Composition • Class A contains Class B. • This statement denotes a strong ownership between Class A, Where Class A is the whole and Class B is its part. • In composition the part class cannot meaningfully exist on its own without the whole class. • Life of Class B is dependent of life of Class A. • For Example, A line item is part of an order so A line item cannot exist without an order. • Remember, Composition, Aggregation and Association as considered as varieties of HAS-A relationship. • It is similar to Master – detail relationship 9

OOPs – Aggregation • The whole class plays a more important role than the

OOPs – Aggregation • The whole class plays a more important role than the part class, but unlike the case of composition, the part class can meaningfully exist on its own without the whole class. • It is similar to a lookup relationship in salesforce. • A player can be part of many teams. 10

OOPs – Associations • Although aggregations represent relationships where you normally only see the

OOPs – Associations • Although aggregations represent relationships where you normally only see the whole, Associations present both the whole and the parts. 11

Comparisons in Aggregations, associations and composition 12 Association Aggregation Composition Class A uses Class

Comparisons in Aggregations, associations and composition 12 Association Aggregation Composition Class A uses Class B. Class A contains Class B , Or Class A has instance of Class B. Class A owns Class B. An association is used when one object wants another object to perform a service for it. An aggregation is used when life of object is independent of container object But still container object owns the aggregated object. A composition is used where each part may belong to only one whole at a time. Life or existence of the associated objects are independent of each other, They just provide some kind of service to each other. Life or existence of the aggregated objects are independent of each other, But one object is playing the role of Owner of the other object. Life or existence of the composite object is dependent on the existence of container object, Existence of composite object is not meaningful without its container object.

OOPs – Inheritance • Inheritance involves acquiring properties from other classes • It represents

OOPs – Inheritance • Inheritance involves acquiring properties from other classes • It represents a IS-A relationship. • There is a true parent/child relationship and The child (or subclass) inherits directly from the parent (or superclass) • Reusability: We can specialize existing classes (types) and write only the code that is changed i. e. we can reuse our existing classes (as base classes) and capitalize on the work already done. • Extensibility: It helps in extending the existing functionality. 13

OOPs – Polymorphism • Polymorphism means the ability to take on many forms, •

OOPs – Polymorphism • Polymorphism means the ability to take on many forms, • The term is applied both to objects and to operations. • Polymorphism is tightly coupled to inheritance and is one of the most powerful advantages to object-oriented technologies. • Polymorphic operation - "One Operation, Many Methods". 14

Apex Introduction Overview of Apex 15

Apex Introduction Overview of Apex 15

Apex – Introduction • Apex is strongly typed, objectoriented programming language. • It allows

Apex – Introduction • Apex is strongly typed, objectoriented programming language. • It allows developers to execute flow and transaction control statements on the Force. com platform server. • The syntax of apex is similar to that of Java and it acts like database stored procedures. • It allows developers to add business logic to system events like button clicks, record updates and visualforce pages. • Apex code can be initiated by webservice requests and from triggers on objects. 16

Apex – Features • Integrated: It provides built in support for DML, SOQL and

Apex – Features • Integrated: It provides built in support for DML, SOQL and SOSL, looping controls, locking syntax, custom public force. com API calls • Easy to use: Syntax and semantics are similar to that of java • Data Focused: Programs will have syntax and semantics related to database languages. • Rigorous: Strongly typed language. • Hosted: It is interpreted, executed and controlled by force. com environment. • Multitenant aware: Apex runs in multitenant environment and the run time engine is designed to guard closely against run time code. It is aware of the governor limits. • Automatically upgradeable: Upgrades are automatically done without any impact to the existing code. • Easy to test: It provides built in support for unit test creation and execution, including test results that indicate how much code is covered. • Versioned: Apex code can be saved against different versions of force. com API in order to maintain the behavior. 17

Apex & Visualforce – When to Use • Use Apex to • Create webservices

Apex & Visualforce – When to Use • Use Apex to • Create webservices • Create email services • Perform complex validation over multiple objects. • Create complex business processes that are not supported by workflows. • Create custom transactional logic • Attach custom logic to an operation. • User Visualforce to • Build wizards and other multistep processes. • Create own flow control through an application. • Define navigation patterns and data specific rules for optimal, efficient application interaction. • Apex cannot be used for • Render elements in the user interface other then error messages • Change standard functionality • Create temporary files • Spawn threads. 18

Apex – Program Structure 19

Apex – Program Structure 19

Apex – How it works 20

Apex – How it works 20

Apex Development Process Overview Of various components involved 21

Apex Development Process Overview Of various components involved 21

Environment Types • Developer Environment • Production Environment • Sandbox Environments • Developer Sandbox

Environment Types • Developer Environment • Production Environment • Sandbox Environments • Developer Sandbox or configuration sandbox • Developer Pro sandbox • Partial Data sandbox • Full Sandbox 22

Points to Introduce • • 23 Developer Console Force. com IDE Deployment Process Overview

Points to Introduce • • 23 Developer Console Force. com IDE Deployment Process Overview Adding Apex Class Adding Apex Trigger Adding a Visualforce Page Log Files In salesforce Adding a Test class

Points to Introduce • • 24 Developer Console Force. com IDE Deployment Process Overview

Points to Introduce • • 24 Developer Console Force. com IDE Deployment Process Overview Adding Apex Class Adding Apex Trigger Adding a Visualforce Page Log Files In salesforce Adding a Test class

Datatypes and Variables Overview Of Datatypes and Variables 25

Datatypes and Variables Overview Of Datatypes and Variables 25

Apex - Datatypes • Primitive Data types • Blob – collection of binary data

Apex - Datatypes • Primitive Data types • Blob – collection of binary data stored as a single object. Usually used for storing documents, attachments etc. • Boolean – true, false – (Checkbox) • Datetime • Decimal • Double • ID – Salesforce Unique Id (15 or 18 digit Id) • Integer • Long • String – Comparison operators can be directly used on strings. • Time • Non –standard Primitive data types • Anytype • Currency – Can only be used with SOQL and SOSL 26

Apex – Data types • Collections • Lists – An ordered collection of elements

Apex – Data types • Collections • Lists – An ordered collection of elements that are distinguishable by indices. List<Datatype> variable. Name = new List<Datatype>(); • Sets – Unordered collection of elements that do not contain duplicates. Set<Datatype> variable. Name = new Set<Datatype>(); • Maps – A collection of key – value pairs where each unique key maps to a single value. • Map<Datatype, Datatype> map. Name = new Map<Datatype, Datatype>(); • Map key can hold the null value • Adding second key with an existing key overwrites the existing key. • Map keys of type string are case sensitive • Enums – An enum is a abstract datatype that can have a collection of finite set of identifiers typically used to define a set of possible values 27

Operators Overview Of Operators 28

Operators Overview Of Operators 28

Apex - Operators • Relational: >, <, >=, <=, ==, != • Assignment: =,

Apex - Operators • Relational: >, <, >=, <=, ==, != • Assignment: =, +=, -=, *=, /=, |=, &= • Logical: &&, ||, ! • Arithmetic: +, -, *, /, % Conversion Rules: • Apex requires us to explicitly convert one data type to another. Some data types can be implicitly converted. Lower types can be assigned to higher types. • Integer • Long • Double • Decimal 29

Control Structures Overview Of Control Structures 30

Control Structures Overview Of Control Structures 30

Apex – Conditional Statements • Simple If If(Boolean Expression) { statements; } • If

Apex – Conditional Statements • Simple If If(Boolean Expression) { statements; } • If else If (Boolean Expression){ Statements; }else{ Statements; } • Nested if If(Boolean Expression){ Statements; ………… } } • Ladder if 31

Loops • Apex supports the following five types of procedural loops • do {statement}

Loops • Apex supports the following five types of procedural loops • do {statement} while (Boolean_condition); • while (Boolean_condition) statement; • for (initialization; Boolean_exit_condition; increment) statement; • for (variable : array_or_set) statement; • for (variable : [inline_soql_query]) statement; • Loops can use the following • Break: exits the entire loop • Continue: skips to the next iteration of loop 32

Classes, Objects and Interfaces Overview Of Classes, Objects and Interfaces 33

Classes, Objects and Interfaces Overview Of Classes, Objects and Interfaces 33

Class - Syntax private | public | global [virtual | abstract | with sharing

Class - Syntax private | public | global [virtual | abstract | with sharing | without sharing | (none)] class Class. Name [implements Interface. Name. List | (none)] [extends Class. Name | (none)] { [public | private | protected | global | final] [static] data_type variable_name [= value]; (public | private | protected | global ) [override] [static] data_type method_name (input parameters) { // The body of the method } } 34

Jayaprakash Narayan Thatiparthi Technical Architect jp. narayan@gmail. com 35

Jayaprakash Narayan Thatiparthi Technical Architect jp. narayan@gmail. com 35