Professional Documents
Culture Documents
Apex Notes-Day 1 & 2
Apex Notes-Day 1 & 2
Programmatic Approach
80-90%(Coding) and 10-20%(Point and Click)
What is a Software?
Software is a set of programs.
What is a Program?
Program is a set of instructions.
Tools:
Developer Console
Visual Studio Code
Variable:is a temporary storage location in the memory that has a name, has an
address, may contain a value and is always associated with a data type.
Sobject ob;
i)Private: private members are accessible only inside the class in which they are
defined.
ii)Protected: protected members are accessible inside the class in which they are
defined and by the child classes also.
iii)Public: public members are accessible in all the classes within Salesforce.
iv)Global:global members are accessible inside salesforce and outside salesforce
also.
Static Members:
-are the members that get memory at the compilation time.
-Static members are allocated memory once throughout the program.
-Static members maintain a single copy and that is shared by all the objects.
-'static' keyword is used to make a member static.
-static members are called by the class name using the dot notation.
-static methods can only use static variables.
Constant members:
-are the members that have fixed value or we can say that they are initialized once
at the time declaration or inside the constructors.
For ex: Pi,GST
-'final' keyword is used to make member constant.
Constructor:
-is a special method that has a same name as of class but preceded by parenthesis.
-do not have return types.
-are used to allocate memory to class.
-are called automatically whenever an instance of a class created.
-constructors can be used to initialize member variables and to call other methods.
-can be overloaded.
Properties:
-are members of a class that can be used to implement encapsulation.
-are composed of get and set accessors.
-set is used to store the value and get is used to return a value.
Interface-PurchaseOrder
Discount()
Employees
Customer
Constructs
i)Conditional Constructs: are used for making decisions
-if else
-check a number if its even or odd.
-if else ladder
-Units<100 then 2rs per unit
-units>100 and <200 then 3rs per unit
-units>200 and <300 then 4rs per unit
-nested if else
Age,Marks,Qual-Selected/rejected
-switch statement
-do while: is an exit controlled loop means condition is checked at the exit time
and hence, it will execute at least once even if the condition is false.
-while: is an entry controlled loop means condition is checked at the entry time.
-for: is a compact loop and is also an entry controlled loop.
-foreach: this loop is used when we are not aware of the size of a collection.
5 schools
10 participants(name,score)
10*2*5=100 variables
School1Name[10],School1Score[10] * 5=10
Syntax:
integer [] Score=new integer [10];//declaration
Score[0]=89;//initialization
Score[1]=67;
Score[2]=78;
System.debug(Score[1]);
Apex Collections:
i)List:
-is a ordered collection of an elements.
-list can have duplicates.
-is best alternative to an array.
-some methods are: add(),size(),contains(),remove(), clear() etc.
Syntax:
List<data_type> Listname=new List<data_type>();
ii)Set:
-is an unordered collection of elements.
-set cannot have duplicates.
-some methods are:add(),contains(),size() etc.
Syntax:
Set<data_type> setName=new Set<data_type>();
iii)Map:
-stores the values in key-value pair.
-values can be duplicated but not the keys.
-some methods are: put(),get(),Values(),keyset(),putAll() etc
Syntax:
Map<data_type,data_type> MapName=new Map<data_type,data_type>();