Platform Material
Platform Material
com Platform:
===================
Salesforce Offers:
1. SAAS: Salesforce CRM
Limits:
1. We Can't arrange the fields in more than 2 columns
inside a
section.
2 Types of Customizations.
Benefits:
1. No need to have the Technical Skills.
2. Easy to implement
3. Each feature will be implemented by using "Mouse
Clicks".
4. It will save the Time.
5. Save the Budget.
Benefits:
1. We can implement Complex Functionalities.
2. We can design the Customized User Interfaces with
attractive Look and Feel.
3. We can implement the Complex Business Logic based
on the application requirement.
Force.com Platform
|
--> 2 Programming Languages.
1. Apex Programming:
Used to implement the Custom
Business Logic.
2. Visualforce Programming:
Visualforce is a Web Development
Framework, to be used to design the Attractive and Dynamic user interfaces with
"Rich Look and Feel".
Apex Programming:
=================
Apex is a Cloud Based Programming Language, which doesn't requires any
installations.
Apex is an Object Oriented Programming Language, Where each business logic will be
available in the form of "Classes and Objects".
By using Apex Programming language, we can implement the Custom Business Logics.
Apex is Not a Case-Sensitive Programming. We can write the code by using any
character case.
Apex is tightly integrated with the Salesforce Objects. Hence we can perform all
the DML operations on the Salesforce objects.
(i.e. We can perform INSERT, UPDATE, DELETE, UNDELETE, UPSERT and MERGE operations
on the Database object records)
By using Apex programming, we can fetch the records from one or more objects with
the help of a Query Language called as "SOQL Queries".
(SOQL --> Salesforce Object Query Language)
By using Apex programming, we can search for the required content in one or more
objects at a time with the help of "SOSL Queries".
(SOSL --> Salesforce Object Search Language)
By using Apex programming, we can process millions of records with the help of
"Batch Programming and Schedule Programming".
By using Apex programming, we can integrate the Salesforce Applications with any
external system with the help of "REST API and SOAP API".
(API ---> Application Programming Interface)
(REST --> Representational State Transfer)
(SOAP --> Simple Object Access Protocol)
Note:
Each Apex Programming Code will get compiled by using "Apex Compiler" and
will get executed by using a Runtime Engine called as "Apex Runtime".
Each Apex Class will get stored inside the "ApexClass" object.
Each Apex class code will get stored inside a file with the extension ".apxc". And
Each Apex Trigger will get stored inside the file with the extension ".apxt".
Developer Console
|
--> TabBar
|
--> Logs Tab.
Data Types:
-----------
DataTypes describes the below 2 things
1. Primitive DataTypes:
It contains the Fundamental / Basic DataTypes provided by apex
programming.
Ex:
Integer, Decimal, Double, Long, String, Boolean, Date,
Time, DateTime, ID, Blob, Object.
Integer:
--------
It allows us to store the Numerical values without any
decimal points.
Note:
Each Number field, Percent field, and currency field
will reference the "Integer DataType".
Boolean:
--------
It allows us to store TRUE / FALSE value.
Note:
Each CheckBox field will reference the "Boolean"
DataType.
ID:
---
It will store either 15 / 18 characters Record ID.
Note:
Each ID Field, Lookup Relationship, Master-Detail
Relationship, Hierarchical Relationship, and External Object Lookup Relationship
fields are referencing the "ID DataType".
String:
-------
Allows us to store a collection of characters. String
values should be enclosed with a Single Quote.
Ex:
'Ramesh', 'Pawan Kumar', 'M'
Note:
Auto Number,Phone, Email, URL, Text, Text Area, Text
Area Long, Text Area Rich, Picklist, Picklist-MaultiSelect, Text Encrypted, Geo
Location, Formula,..etc.
Date:
-----
Allows us to store the Date Value.
Note:
Each Date Field will reference the Date DataType.
Time:
-----
Allows us to store the Time Value either in 12 / 24 hours
format.
Note:
Each Time Field will reference the Time DataType.
DateTime:
---------
Allows us to store the DateTime stamp Value.
Note:
Each DateTime Field will reference the DateTime
DataType.
Long:
-----
It allows us to store the Larger Integer values without any
decimal points.
Decimal:
--------
It allows us to store the Numerical values including the
decimal digits inside the variable.
Ex:
150.50
175.20
Note:
Each Currency field will reference the Decimal
Datatype by default.
Double:
-------
It allows us to store the Numerical values with more number
of decimal digits inside the variable
Ex:
10 / 3 = 3.3333333333333
3.1412
Note:
Each Document object will reference the Blob
DataType.
Object:
-------
It allows us to store any of the value inside the variable.
It is a Generic DataType.
Ex:
Account, Contact, Opportunity, Lead, Case, Solution, Order,
Contract, Quote, ....etc, Position__C, Candidate__C, Loan__c, Student__C,
Hiring_MAnager__C,...etc.
Variables:
==========
Variable is nothing but a name to be get allocated for the memory location to
locate the value.
Variables are used to store the values temporarily inside the application during
the execution.
We can define one or more variables inside the application.
Syntax:
[Access Specifier] <DataType> <variableName> [= <Value>];
Ex:
integer customerCode;
string customerName;
string customerAddress;
Decimal balanceAmount;
Date birthDate;
Boolean isActive;
Note:
We can define the multiple variables in a single line as below.
Ex:
integer customerCode, age;
string customerName, address, designation;
Decimal balanceAmount, loanAmount;
Date birthDate, joiningDate, reievingDate;
Note:
Upon defining the variables, if the user didn't assigned any value, then Apex
will store the value as "Null" inside the variable.
Syntax:
<variableName> = <Value>;
Ex:
customerCode = 100001;
age = 34;
customerName = 'Pawan Kumar';
Address = '#412, Satya Sai Apartments, Hyderabad';
balanceAmount = 12500.50;
Note:
We can define the variable and initialize the value for the variable in a
single line as below.
Ex:
integer productCode = 4000012;
string productName = 'Laptop Device';
decimal unitPrice = 35000;
Boolean isInStock = true;
Operators:
==========
Operator is nothing but a symbol, which is used to perform the operations on
the operands.
+
-
*
/
Math.Mod()
Ex:
5/2 = 2 (Quotient)
Math.Mod(5,2) = 1 (Reminder)
3. Logical Operators:
These re used to prepare the Compound conditions by grouping the
multiple conditions together.
Ex:
integer customerCode = 1001;
customerCode++; --> o/p: 1002
5. Assignment Operators
+=
-=
*=
/=
=
Ex:
integer balanceAmount = 25000;
C --> Printf("Message");
C++ --> Cout<<"Message";
Java --> System.Out.Println("Message");
C#.Net --> Console.WriteLine("Message");
Syntax:
System.debug('Message to Print in Debug Log File.');
Ex:
System.debug('Welcome to Apex Programming.');
system.debug('This is my First Apex Program.');
Navigation:
Click on your name and expand it.
1. Click on "Developer Console" link.
2. Goto the "Debug" menu and expand it.
3. Click on "Execute Anonymous Window" link.
(OR)
From Developer Console, use the ShortCut "CTRL+E".
4. Write the Code inside the Editor.
5. Click on "Execute / Execute Highlighted" button.
6. View the Result inside the Debug Log File.
UseCase:
========
Write an apex program, to print the Welcome message on the Debug Log file.
Step 1:
Goto the Execute Anonymous Window.
Step 2:
Write the required code inside the Editor.
Step 3:
Select the CheckBox "Open Log".
Step 4:
Click on "Execute / Execute Highlighted".
Step 5:
Goto the "Developer Console" and Select the
CheckBox "Debug Only".
Step 6: View the Result.
UseCase:
========
Write an apex program, to define Two variables and print the values on the
Log File.
integer customerCode;
string customerName;
System.debug(customerCode);
System.debug(customerName);
system.debug('--------------------------------------------');
UseCase:
========
Write an apex program, to define the Two Integer variables and assign the
values and perform all the mathematical operations.
firstNumber = 1000;
secondNumber = 50;
UseCase:
========
Write an apex program, to Calculate the Simple Interest.
principleAmount = 5000;
tenure = 10;
rateOfInterest = 4;
UseCase:
========
Write an apex program, to print the Sum of first 100 Numbers.
Formula:
1 + 2 +3 +4 +5 +........+ 100 = n (n+1)
-------
2
integer maxNumber, totalSum;
maxNumber = 50;
Assignments:
============
1. Write an apex program, to calculate the BillAmount based on the Quantity
and UnitPrice.
Conditional Statements:
=======================
1. IF Condition
2. Switch Statement (Summer'18 Release)
3. Ternary Operator
IF Condition:
=============
By using the IF Condition, we can add one or more user defined conditions to
be get verified before executing the statements.
If the conditions are satisfied, then it will execute the Statements. Else it
will skip the execution of the statements.
By using IF conditions, we can change the control flow of the program
execution.
1. Simple IF Conditions
2. If Else Condition.
3. Else If Condition
4. Nested IF Condition
Simple IF Condition:
--------------------
Syntax:
If(<Conditions>)
{
// Write the Statements..
}
Note:
Each Condition should follow the below syntax..
Syntax:
<VariableName> <operator> <Value>
Ex:
Rating == 'Hot'
SecondNumber > 0
Industry == 'Finance'
Phone != Null
isActive == true
UseCase:
--------
Write an apex program, to perform the Mathematical operations on the
Two Numerical values.
firstNumber = 1000;
secondNumber = 0;
if(secondNumber > 0)
{
result = firstNumber / secondNumber;
system.debug('Division Result is....: '+ result);
If Else Condition:
------------------
Syntax:
If(<Conditions>)
{
// Write the Statements.. (True Block Statements)
}
else
{
// Write the Statements.. (False Block Statements)
}
UseCase:
--------
Write an apex program, to perform the Mathematical operations on the Two Numerical
values.
firstNumber = 1000;
secondNumber = 0;
if(secondNumber > 0)
{
result = firstNumber / secondNumber;
system.debug('Division Result is....: '+ result);
/*
Write an apex program, to find out the Biggest Number from the Given Two
Numbers.
*/
firstNumber = 4500;
secondNumber = 6700;
UseCase:
--------
Write an apex program, to find out the Student Result as below.
1. We have the 5 Subjects (English, Maths, Physics, Chemistry, Hindi)
2. PASS: If the student got more than 40 Marks in each subject.
3. FAIL: IF the student got less than 40 marks in any of the subject.
if(maths >= 40 && physics >= 40 && hindi >=40 && english >= 40 && chemistry >= 40)
{
System.Debug(PASS);
}
else
system.debug(FAIL)
UseCase:
--------
Write an apex program, to find out the Bill Amount of the Customer based on
the Quantity and Unit Price. And offer the discount as below.
1. Amount > 10,000, then Offer 20% discount.
2. Else No Discount provided to Customer.
Else IF Condition:
==================
Syntax:
IF(<Conditions>)
{
// Write the Statements..
}
else if(<Conditions>)
{
// Write the Statements..
}
else if(<Conditions>)
{
// Write the Statements..
}
...
...
else
{
// Default Block Statements..
}
This feature is used to prepare the multiple branches of conditions from which only
one branch statements will be executed at a time.
If any of the branch conditions are matching / satisfied, then it will execute the
associated block of statements.
If all the branch conditions are failed, then it will execute the "Else Block
Statements".
UseCase:
--------
Write an apex program, to find out the Biggest Number from the given two
numbers.
firstNumber = 114500;
secondNumber = 2314500;
if(firstNumber == secondNumber)
{
system.debug('Both the Numbers are Identical.');
}
else if(firstNumber > secondNumber)
{
system.debug('First Number is the Biggest One.');
}
else
{
system.debug('Second Number is the Biggest One.');
}
/*
Write an apex program, to print the Season Name based on the Month Number as
below.
/*
Write an apex program, to print the Month Name based on the Month Number as
below.
Nested IF Condition:
====================
By using this feature, we can include / insert an if condition into an another
condition to achieve the complex functionalities.
Syntax:
If(<Conditions>)
{
// Write the Statements..
}
else
{
// Write the Statements..
if(<Conditions>)
{
// Write the Statements..
if(<Conditions>)
{
// Write the Statement...
}
}
else
{
// Write the Statements..
}
}
/*
Write an apex program, to find out the Student Result and Grade as below.
english = 72;
hindi = 81;
maths = 19;
physics = 79;
chemistry = 86;
if(english >= 40 && maths >= 40 && hindi >= 40 && physics >= 40 && chemistry
>= 40)
{
system.debug('Congratulations..!! You got PASSED.');
system.debug('Total Marks are....: '+ total);
average = total / 5;
system.debug('Average Marks are....: '+ average);
Switch Statement:
=================
Switch Statement is used to compare the variable / expression value with the
various branches.
If any of the Branch Value is matching with the expression, then it will execute
the associated block of statements.
If any of the Branch value is not matching with the expression, then it will
execute the default block statements.
Syntax 1:
---------
Switch ON <Expression / Value>
{
When <Value1>
{
// Write the Statements..
}
When <Value2>
{
// Write the Statements..
}
When <Value3>
{
// Write the Statements..
}
...
...
When Null
{
// Write the Statements..
}
When Else
{
// Default Block Statements..
}
}
UseCase:
--------
Write an apex program, to print the Day Name based on the Day Number as
below.
Switch ON dayNumber
{
When 1
{
system.debug('Monday.');
}
When 2
{
system.debug('Tuesday');
}
When 3
{
system.debug('Wednesday');
}
When 4
{
system.debug('Thursday');
}
When 5
{
system.debug('Friday');
}
When 6
{
system.debug('Saturday');
}
When 7
{
system.debug('Sunday');
}
When Else
{
system.debug('Invalid Day Number.');
}
}
Syntax 2:
---------
Switch ON <Expression / VariableName>
{
When <Value1>,<Value2>,<Value3>,...,<ValueN>
{
// Write the Statements..
}
When <Value11>,<Value21>,<Value31>,...,<ValueN1>
{
// Write the Statements..
}
...
...
When Else
{
// Write the Default Block Code..
}
}
In this feature, it will compare the Variable / expression value with a collection
of elements.
if any of the branch element is matching with the expression, then it will execute
the block of statements.
If any of the branch value is not matching with the expression, then it will
execute the Default Block Statements.
/*
Write an apex program, to print the Season Name based on the Month Number as
below.
Switch ON monthNumber
{
When 1, 2, 3, 4
{
system.debug('Winter Season.');
}
When 5,6,7,8
{
system.debug('Summer Season.');
}
When 9,10,11,12
{
system.debug('Spring Season.');
}
When else
{
system.debug('Invalid Month Number. Please Enter the Number
between 1 - 12.');
}
}
Iterative Statements:
=====================
These are used to execute a block of statements iteratively / continuously till the
required number of times based on the application requirement.
By using Iterative Statements, we can reduce the number of lines of code. So that
we can avoid the Duplicate code and we can improve the application performance.
1. While
2. Do-While
3. For
4. Enhanced FOR Loop.
While Statement:
================
Syntax:
While(<Conditions>)
{
// Write the Statements..
}
It will execute the statements iteratively till the specified conditions get
satisfied. Once the Condition get failed, then it will comes out of the block
automatically.
/*
Write an apex program, to Print the Welcome Message 10 Times on the Debug Log
File.
*/
integer counter = 1;
counter++;
}
/*
Write an apex program, to print the Numbers between 1 - 100.
*/
integer counter = 1;
counter++;
}
/*
Write an apex program, to Print the Even Numbers between 1 - 50
*/
integer counter = 2;
counter += 2;
}
Assignments:
============
1. Write an apex program, to print the Odd Numbers between 1 - 100.
4. Write an apex program, to Check whether the given number is an Even Number
or not.
/*
Write an apex program, to print the Mathematical Table for the given number
as below.
(
Ex:
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
...
...
5 * 10 = 50
)
*/
counter++;
}
Do-While Statement:
===================
Syntax:
Do
{
// Statements..
...
...
}While(<Conditions>);
It will continuously execute the statements till the condition get satisfied.
Once the Condition get failed, then it will comes out of the block.
/*
Write an apex program, to print the Odd Numbers between 1 - 50 in reverse
order.
*/
Do
{
system.debug('Odd Number is....: '+ counter);
counter -= 2;
}While(counter >= 1);
Assignments:
------------
1. Write an apex program, to check whether the given Number is a Prime Number
or not.
(Ex: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,...etc.)
FOR Loop:
=========
Syntax:
for(<Initialization Part>; <Conditions Part>; <Increment / Decrement Part>)
{
// Write the Statements..
...
...
}
/*
Write an apex program, to Print the Mathematical Table for the given number.
*/
Arrays:
=======
Arrays are used to hold a collection of Homogeneous Elements. i.e. Arrays can store
a collection of similar DataType elements.
While Creating the Array, we have to specify the "Size", which describes the number
of elements can be hold inside the array.
We can't Increase / Decrease the Array Size at runtime. So, arrays causes the
memory wastage.
Each Element inside the array will be identified by using an "Index Position"
starting from "Zero".
Each element inside the array will be identified by using "Array Name along with
the Index Position".
Syntax:
<Datatype>[] <arrayName> = new <DataType>[Size];
Ex:
Integer[] customerCodes = new Integer[10];
|
--> Holds 10 Integer elements.
Syntax:
<arrayName>[IndexPosition] = <Value>;
Ex:
Integer[] customerCodes = new Integer[10];
customerCodes[0] = 1190045;
customerCodes[1] = 6677;
customerCodes[2] = 9900;
Syntax:
<ArrayName>[IndexPosition];
Ex:
System.debug('Customer Code is...: '+ customerCodes[0]);
System.debug('Customer Code is...: '+ customerCodes[1]);
UseCase:
--------
Define an Array and Print the Array Elements on the Debug Log File.
// Defining an Array..
Integer[] customerCodes = new Integer[5];
system.debug('------------------------------------------');
system.debug('----------------------------------------');
/*
Define an Array to manage a collection of string elements, and assign the
elements
upon defining the array.
*/
// String Array..
string[] countryCodes = new string[]
{'India','USA','UK','Japan','China','Germany','Middle East'};
system.debug('----------------------------------');
// Integer Array..
Integer[] employeeCodes = new Integer[]{1001, 1002, 1003, 1004, 5600};
Assignments:
============
1. Write an apex program, to Manage a collection of Employee Names by using
Arrays.