Nothing Special   »   [go: up one dir, main page]

Salesforce Dev Notes - PDF - Constructor (Object Oriented Programming) - Programming

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

Search Read free for 30 days

Download
Documents now  Programming
 Computers 2 of 25  Search document 

 0% (2) · 1K views · 25 pages


Salesforce Dev Notes
Uploaded by Vasu Vasu on Jan 30, 2021

Salesforce devleoper practise notes Full description

     
Save 0% 100% Embed Share Print

Download now 2 of 25  Search document 

Salesforce Development:
-----------------------------------------------
APEX:
Apex is a strongly typed object-oriented programming language.
It allows the developers to execute ows and transacon control statements
Apex enables developers to add business logic
When should I use Apex:
To create email service
Create webservices
Perform complex validaon over mulple objects
To create complex business processes that are not supported by workow
Create custom transacon logic
Aach custom logic to another operaon
How does apex work:
All apex programs run enrely on-demand on force.com plaorm

Developer Force.com Plaorm

Uncompiled Apex

App Server Compiled Apex

Meta data
Internet
Request Apex Request

Apex Runme

Result Compiled Apex

End User

First, app server compiles the code into set of instrucons that can be understood by the runme
interpreter.
The complete code is stored to meta data.
When the end user triggers the execuon of apex by clicking the buon or VF page, the app server
retrieves the compiled instrucons from the metadata and send them to run me interpreter before
returning the result.

OOPS:
In oops, programs are organized around objects and data rather than logic and acons.
OOPS is a methodology that provides a way of modularizing a program by creang paroned
memory area for both data and methods that can be used as template for creang copies of such
modules(objects) on demand
The main oops principles are:
1.Encapsulaon
2.Inheritance
3.Polymorphism
1.Encapsulaon: The wrapping up of data and methods together is called encapsulaon.
2.Inheritance: It creates new classes from exisng classes, so that the new classes will acquire all the
features of the exisng classes.
3.Polymorphism: It represents one form in mulple forms
------------------------------------------------------
 

Apex Fundamentals:

of 25 type of data can be stored.


Data types: Data types in apex tells about what
  There are 3 types:
i)Primive data types
ii)Collecons
iii) Enums
i)Primive data types: These are the data types which are predened by the apex.
All primive data types are passed by value, not by reference
Apex primive data types include:
Boolean Date Time Dateme
Integer Long Double Decimal
#All Apex variables are inialized to null.

Sobjects:
Sobjects are short for “Salesforce Objects”.
An Sobject can be generic sobject or be a specic sobjects such as Account,Contact or
MyCustomer__c.
Sobjects are standard or custom objects that stores record data in the force.com database.
Developers refer to sobjects and their elds by their API Names.
Class: Class is a collecon of data members and methods.

Eg:
Class student
  {
Integer no; Data members of class
String name;
Public void getdetails ()
{
System. Debug (‘Roll no’ +no); Method of class
System. Debug (‘Name’ +name);
}
}

 How to dene an apex class specify the following:


i)Access Modiers:
-We must use one of the access modiers for top level class (public or global).
-We should not have to use access modiers in the declaraon of inner classes.
ii)Oponal denion modiers such as virtual and abstract
iii)Required are the keyword ‘Class’ followed by class name
iv)Oponal extensions include AND/OR implementaons.

SYNTAX:

Private|public|global [virtual|abstract|with sharing|(none)] class className [implements


interfaceNameList|(none)] [extends className|(none)]
{
The body of the class
}
Access Modifers:

Private: If a class is declared private it is only known to the block in which it is declared.
 

###### By default, all the inner classes are private.


Public: If a class is declared public, it is visible throughout the applicaon and you can access the app.
Anywhere.
of 25 
Global: If a class is declared global, this apex class is visible to all the apex applicaons in the applicaon or
outside the applicaon.
###### If the method or inner class is declared a s global then the top-level class also must be declared as
global.
With Sharing: If the class is declared as a with sharing, sharing rules given to the current user will be taken
into the consideraon and the user can access and perform the operaons based on the permissions given
to him on objects and elds (eld level security, sharing rules).
Without sharing: If a class is declared as a without sharing then this apex class runs in system mode which
means apex code has access to all the objects and elds irrespecve of current users sharing rule, eld
level security, object permissions.

Points to be noted:
-If a class is not declared as with sharing or without sharing then by default the class is executed in system
mode i.e., without sharing.
-Both inner classes and outer classes can be declared as with sharing
-If the inner class is with sharing and top-level class is without sharing then by default enre context will
run in with sharing context.
- If a class in not declared as with/without sharing and if this class is called by another class in which
sharing is enforced then both the classes run with ‘with sharing’.
-If outer class is with sharing and inner class is without sharing then the enre class runs in without sharing
context only.
##Inner classes don’t take the sharing properes from outer class
-Virtual: If a class is declared with keyword- virtual then this class can be extended (Inherited) or this class
methods can be overridden by using a class called overridden
-Abstract: This class contains abstract methods

Class Variables: The variables in the class should specify the following properes when they are dened.
i)Oponal: modiers such as public or nal or stac
ii)Required: the data types of the variable
iii)Required: the value of the variable
iv)oponal: the name of the variable

SYNTAX: [public|private|protected|global|nal] [stac] data_type variable_name


E.g.
Private stac nal Integer My_Int;
Private nal integer i=1;
Class Methods: To dene the methods specify the following
i)Oponal: Modiers such as public or protected
ii)Required: The data type of the value returned by the method such as string or integer. Use void if no
value is returned.
iii)Required: a list of input parameters for the method separated by commas, each preceded by its data
type and enclosed in parentheses (). If no parameters use a set of empty parentheses.
##A method can only have 32 input parameters
iv)Required: The body of the method, enclosed in braces {}. All the code for the method including any local
variable declaraons is contained here.

SYNTAX: 
(public|private|protected|global) [override] [stac] data_type method_name (input parameters)
{
 

//body of the method


}
of 25 

E.g.
Public stac integer getInt ()
{
Return my_Int;
}
E.g.
Public class example
{
Public integer show (Integer age)
{
System. Debug(‘My age is ’ +age);
}
}

Object: Object is an instance of the class. This has both state and behavior.
#Memory for the data members are allocated only when an object is created.
SYNTAX:
ClassName objectname = new ClassName ();

Name of the Keyword which


class for which It is a reference we are
we are creang variable allocang the   Constructor
an object memory

E.g.:
  Class Example
{
//code
}

Example e = new Example ();

Constructor: Constructor is a special method which have the following properes


i) Method name will be the same as the class name
ii) Access speciers will be public
iii) This method will be invoked once only at the me of object creaon
iv) This is used to instanate the data members of the class
E.g.:
Public class TestObject
{
//The no argument constructor
Public TestObject ()
{
//code
 

}
}
of 25
There are 3 types of constructors… 
1)Default constructor
2)Non parameterized constructor
3) Parameterized Constructor

1)Default Constructor:
Is an apex class does not contain any constructor then apex compiler by default creates a
dummy constructor on the name of the class when we create an object for the class.
E.g:
Public class Example
{

}
Example e = new Example ();

In the above example the apex class does not contain any constructor. So when we create object
for Example class the apex compiler creates a default constructor as…

Public example ()
{
 }

2)Non parameterized constructor and parameterized constructor:


It is a constructor that doesn’t have any parameters or constructor that has parameters.
E.g.:
Public class Example
{
Integer rno;
String name;
Public Example (Integer x, string myname)
{
rno = x; parameterized
name = myname;
}
Public Example ()
{
//code
rno = 10; Non-parameterized
name = vasu;
}
}

Usage of Apex program in visual force page:


1) When we want to call Apex class in VF page, we have to declare in the following format.
<Apex: page controller = “classname”>

Whenever we call a vf page in which controller aribute is dened


It will rst create an object for the apex class which is dened in controller.
2) When object is created for the apex class rst it invokes the constructor.
 Referring to the apex class members in VF:
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 
of 25 

Reward Your Curiosity


Everything you want to read.
Anytime. Anywhere. Any device.

Read free for 30 days

No Commitment. Cancel anytime.

Share this document


    
You might also like
of 25 
Ebook 221 pages

Hibernate, Spring & Struts Interview Questions You'll Most Likely Be Asked
Vibrant Publishers
No ratings yet

Document 22 pages

DOC-20190813-WA0088.docx
Shifanila
No ratings yet

Document 23 pages

Tutorial
Golf Romeo
No ratings yet

Document 47 pages

C Sharp Objects
Sai Praveen
No ratings yet

Document 10 pages

OOPS Long
abc ker
No ratings yet

Document 19 pages

Day 2 Oops Concepts


Pradeepthi Bonthala
No ratings yet
Document 38 pages
of 25 
Lecture-1_CSE-225 Tamanna Motahar NSU
Md. Al-Amin Ahmed 1712249630
No ratings yet

Document 77 pages

My C++
snathick
100% (1)

Document 8 pages

asp_oct_2013
Jainish Shah
No ratings yet

Document 31 pages

C++ COMPREHENSIVE VIVA


aj
No ratings yet

Document 10 pages

Top 50 C# Interview Questions and Answers (1)


Romil
No ratings yet

Document 18 pages

Question Bank
Parimala Vimal
No ratings yet
of 25 
of 25 

Related titles

Ebook Document Document Document Document Document Docu

Hibernate, Spring DOC-20190813- Tutorial C Sharp Objects OOPS Long Day 2 Oops Lec
& Struts Intervi… WA0088.docx Added by Golf Romeo Added by Sai Praveen Added by abc ker Concepts 225
Vibrant Publishers Added by Shifanila Added by Pradeepth… Add

0 ratings 0 ratings 0 ratings 0 ratings 0 ratings 0


0 ratings

About Support Legal Social

About Scribd Help / FAQ Terms Instagram

Press Accessibility Privacy Twitter

Our blog Purchase help Copyright Facebook

Join our team! AdChoices Cookie Preferences Pinterest

Contact us Publishers Do not sell or share my


personal information
Invite friends

Gifts

Scribd for enterprise

Get our free apps

Audiobooks • Books • Documents • Magazines • Podcasts • Sheet music • Snapshots

Language: English

Copyright © 2023 Scribd Inc.

You might also like