Salesforce CRM Study Material No 2
Salesforce CRM Study Material No 2
What is CRM ?
SALESFORCE
CRM ➢ C-R-M stands for Customer Relationship
Management.
➢ It is used to manage and analyze customer
interactions and data throughout
the customer lifecycle.
➢ CRM works to increase profits by producing greater
sales volume.
2. What is Cloud Computing?
SALESFORCE
➢ Cloud computing is the delivery of computing
CRM services like servers, storage, databases, networking
and software over the Internet.
you can retrieve and deploy access settings for the following
managed components in profiles and permission sets:Apex classes
• Custom apps
• Custom field permissions
• Custom object permissions
• Custom tab settings
• External data sources
• Record types
• Visualforce pages
➢ Types of Profile.
SALESFORCE • Standard profiles: By default, salesforce provides
CRM below standard profiles. We cannot delete standard
ones.
• Read Only, Standard User, Marketing User,
Contract Manager, Solution Manager & System
Administrator.
• Each of these standard ones includes a default set
of permissions for all of the standard objects
available on the platform.
• Custom Profiles: Custom ones defined by us. They can
be deleted if there are no users assigned to that
particular one.
➢ How to create a profile in salesforce?
SALESFORCE
Please follow the below link for guidance
CRM https://help.salesforce.com/articleView?id=admin_user
profiles.htm&type=5
➢ What is Role in salesforce?
SALESFORCE
Depending on your sharing settings, roles can control
CRM the level of visibility that users have into your Salesforce
data. Users at any given role level can view, edit, and
report on all data owned by or shared with users below
them in the role hierarchy, unless your sharing model for
an object specifies otherwise.
➢ How to create Role in salesforce?
Please follow the below link for guidance
https://help.salesforce.com/articleView?id=000001047
&language=en_US&type=1
➢ Difference between Profiles and Roles in salesforce?
SALESFORCE A profile contains user permissions and access settings
CRM that control what users can do within their organization.
Profiles control standard and custom
apps, tabs, permissions, Apex classes
and Visualforce pages, etc. users can view.
•
• s it possible to edit the process once it is
SALESFORCE activated?
CRM No, You need to clone and while cloning you can
create new process or create new version.
•
• // populating the map with account id and account
object
• accountIdMap .put(acc1.id,acc1);
SALESFORCE
• accountIdMap .put(acc2.id,acc2);
CRM
• accountIdMap .put(acc3.id,acc3);
•
•}
•
•}
• What is Apex trigger in salesforce?
SALESFORCE
A trigger is the piece of code that executed before and
CRM after a record is Inserted/Updated/Deleted from the
force.com database.
Syntax :
• Trigger <trigger name> on <Object name> (trigger
Events) {
• // Implement the Logic here
•}
• Types of Triggers:
SALESFORCE – Before Triggers
CRM – After Triggers
• Before Trigger: Before triggers are used to perform
the logic on the same object and specifically we
cannot use the DML operation (Insert, update,
delete) on these triggers. These triggers fired before
the data saved into the database.
• After Trigger: After triggers are used to perform the
logic on the related objects and these triggers are
used access the fields values that are created by
system (Ex: CreatedBy, LasteModifiedBy , Record Id
etc..).
• Bulk Triggers:
SALESFORCE By default, every trigger is a bulk trigger which is used
CRM to process the multiple records at a time as a batch.
For each batch of 200 records.
• All the trigger context variables prefixed with
“Trigger.” (Ex: Trigger.isInsert, etc..)
• isInsert: Returns true if the trigger fired due to insert
operation
• isUpdate: Returns true if the trigger fired due to the
update operation.
• isDelete: Returns true if the trigger fired due to
delete operation.
• isBefore: Returns true if the trigger fired before the
record saved.
• isAfter: Returns true if the trigger fired after the
SALESFORCE record saved.
CRM • New: Returns a list of the new version of sObject
records.
• Old: Returns a list of an old version of sObject
records.
• NewMap: Returns a map of a new version of sObject
records. (map stored in the form of
map<id,newRecords>)
• OldMap: Returns a map of an old version of sObject
records. (map stored in the form of map<id,
oldRecords>)
• Size: Returns an integer (total number of records
SALESFORCE invoked due to trigger invocation for the both old
CRM and new)
• isExecuting: Returns true if the current apex code is a
trigger.
SALESFORCE
CRM Trigger Event Trigger.New Trigger.newMap Trigger.Old Trigger.OldMap
Before Insert Yes No No No
Before Update Yes Yes Yes Yes
Before Delete No No Yes Yes
After UnDelete Yes Yes No No
After Insert Yes Yes No No
After Update Yes Yes Yes Yes
After Delete No No Yes Yes
• Trigger Context Variable considerations:
SALESFORCE – Trigger.Old is always read-only
CRM – We cannot delete trigger.new
– In before triggers, trigger.new can be used to
update the fields on the same object.
– In After trigger, we get a runtime exception when
the user tries to modify the fields in the same object.
• What is Apex class in salesforce?
SALESFORCE
As in Java, you can create classes in Apex. A class is a
CRM template or blueprint from which objects are created.
An object is an instance of a class. For example, the
PurchaseOrder class describes an entire purchase
order, and everything that you can do with a purchase
order. ... A class can contain variables and methods.
<apex:page standardController="Account">
<apex:pageBlock title="Hello {!$User.FirstName}!">
You are viewing the {!account.name} account.
</apex:pageBlock>
<apex:detail/>
</apex:page>
<apex:page standardController="Account"
SALESFORCE showHeader="true"
CRM tabStyle="account" >
<style>
.activeTab {background-color: #236FBD; color:white;
background-image:none}
.inactiveTab { background-color: lightgrey;
color:black;
background-image:none}
</style>
<apex:tabPanel switchType="client"
selectedTab="tabdetails"
id="AccountTabPanel" tabClass='activeTab'
SALESFORCE
inactiveTabClass='inactiveTab'>
CRM
<apex:tab label="Details" name="AccDetails"
id="tabdetails">
<apex:detail relatedList="false" title="true"/>
</apex:tab>
<apex:tab label="Contacts" name="Contacts"
id="tabContact">
<apex:relatedList subject="{!account}"
list="contacts" />
</apex:tab>
<apex:tab label="Opportunities"
name="Opportunities"
SALESFORCE
id="tabOpp">
CRM
<apex:relatedList subject="{!account}"
list="opportunities" />
</apex:tab>
<apex:tab label="Open Activities"
name="OpenActivities"
id="tabOpenAct">
<apex:relatedList subject="{!account}"
list="OpenActivities" />
</apex:tab>
<apex:tab label="Notes and Attachments"
name="NotesAndAttachments"
SALESFORCE id="tabNoteAtt">
</apex:page>
Redirecting to a Standard Object List Page
• For buttons or links that navigate a user to a standard
tab, you can redirect the content to present a list of
SALESFORCE
standard objects.
CRM
• • Create a Visualforce page with the following markup:
<apex:page action="{!URLFOR($Action.Account.List,
$ObjectType.Account)}"/>
<apex:page standardController="Account">
<apex:form>
SALESFORCE <apex:pageBlock title="Hello {!$User.FirstName}!">
CRM
You are viewing the {!account.name} account.
<p/>
Change Account Name: <p/>
<apex:inputField value="{!account.name}"/> <p/>
<apex:commandButton action="{!save}"
CRM </apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page
https://Salesforce_instance/apex/myPage?id=enterid
The label attribute can be set on the following
Visualforce components:
SALESFORCE <apex:inputCheckbox>
CRM <apex:inputField>
<apex:inputSecret>
<apex:inputText>
<apex:inputTextarea>
<apex:outputField>
<apex:outputText>
<apex:selectCheckboxes>
<apex:selectList>
<apex:selectRadio>
<apex:form>
<apex:outputField value="{!Location.country}">
CRM </apex:outputField>
<apex:outputField value="{!Location.state}">
</apex:outputField>
<apex:outputField value="{!Location.city}">
</apex:outputField>
</apex:outputPanel>
</apex:form>
Related list :
PDF Convert:
<apex:page standardController="Account"
renderAs="pdf" applyBodyTag="false">
<head>
<style>
body { font-family: 'Arial Unicode MS'; }
.companyName { font: bold 30px; color: red; }
</style>
</head>
<body>
SALESFORCE <center>
CRM <h1>New Account Name!</h1>
<apex:panelGrid columns="1" width="100%">
<apex:outputText value="{!account.Name}"
styleClass="companyName"/>
<apex:outputText
value="{!NOW()}"></apex:outputText>
</apex:panelGrid>
</center>
</body>
</apex:page>
Building a Table of Data in a Page
Some Visualforce components, such as
SALESFORCE <apex:pageBlockTable> or <apex:dataTable>,
CRM allow you to display information from multiple records
at a time by iterating
over a collection of records. To illustrate this concept,
the following page
uses the <apex:pageBlockTable> component to list the
contacts associated with
an account that is currently in context:
Building a Table of Data in a Page
SALESFORCE <apex:page standardController="Account">
CRM <apex:pageBlock title="Hello {!$User.FirstName}!">
You are viewing the {!account.name} account.
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:pageBlockTable value="{!account.Contacts}"
var="contact">
<apex:column value="{!contact.Name}"/>
<apex:column value="{!contact.MailingCity}"/>
<apex:column value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
https://Salesforce_instance/apex/myPage?id=001x000
xxx3Jsxb
SALESFORCE
CRM Editing a Table of Data in a Page
In the last tutorial, you built a table of data. Using
<apex:inputField>
in the data table columns, you can create a table with
editable fields.
Using <apex:commandButton> you can save the data
you change. Any message (
such as Saving) is automatically displayed with the
<apex:pageMessages> tag.
The following page creates a page that enables you to
edit a series of Industry types at the same time:
https://Salesforce_instance/apex/myPage?id=001x000
xxx3Jsxb
SALESFORCE
CRM Editing a Table of Data in a Page
In the last tutorial, you built a table of data. Using
<apex:inputField>
in the data table columns, you can create a table with
editable fields.
Using <apex:commandButton> you can save the data
you change. Any message (
such as Saving) is automatically displayed with the
<apex:pageMessages> tag.
The following page creates a page that enables you to
edit a series of Industry types at the same time:
<apex:page standardController="Account" recordSetVar="accounts"
tabstyle="account" sidebar="false">
<apex:form>
<apex:pageBlock >
SALESFORCE <apex:pageMessages />
CRM <apex:pageBlockButtons>
</apex:pageBlockButtons>
<apex:column value="{!a.name}"/>
<apex:column headerValue="Industry">
<apex:inputField value="{!a.Industry}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_q
uick_start_query_params_getting.htm
SALESFORCE
CRM
SALESFORCE
CRM • PageBlockTable:
• PageBlockTable should be define inside pageblock or
pageblocksection.
• PageBlockTable uses standard styles sheets to design
a visualpage.
• It has the required attribute "value".
• Column headers will be displayed automatically.
<!-- Page: -->
<apex:page standardController="Account">
<apex:pageBlock title="My Content">
SALESFORCE
<apex:pageBlockTable value="{!account}" var="item">
<apex:column value="{!item.name}"/>
CRM </apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
--
• What is custom controller? why we go for custom
controllers?
• Standard controllers provides only built in standard
SALESFORCE functionality to visualforce pages, such as Save, Edit,
CRM Cancel & Delete etc….
• We cannot customize/develop our own functionality
by using standard controllers. By using custom
controllers we can write our own functionality or
override existing functionality. Custom controller is
an Apex Class developed by us. See the below
syntax to define custom controller in visualforce
page.
• <apex:page Controller=”ControllerName”>
• What is controller extension? Controller extension is
custom/additional behavior to standard controllers.
Extension is an apex class. We can add number of
extensions to visualforce page. See below syntax to
• <apex:page Controller=”ControllerName”
extensions=”Class1, Class2,..”>
• We can use Stnadard controller/ Custom Controller
SALESFORCE and extensions at a time. But we cannot use
CRM Standard controller & Custom controller at a time.
See below syntax to understand.
• <apex:page standardController=”ControllerName”
extensions=”Class1, Class2,..”> Correct
• <apex:page Controller=”MYControllerName”
extensions=”Class1, Class2,..”> Correct syntax
• <apex:page
standardController=”MYControllerName”
Controller=”MyController”> Wrong
• Controller Extension
• public myControllerExtension(ApexPages.StandardController
stdController) {
• this.acct = (Account)stdController.getRecord();
• }
• }
• }
<apex:page standardController="Account"
extensions="myControllerExtension">
• {!greeting} <p/>
• <apex:form>
SALESFORCE • <apex:inputField value="{!account.name}"/> <p/>
• </apex:page>
<apex:page Controller="AddmultipleAccountsController">
<apex:form >
<apex:pageBlock >
<apex:inputField value="{!acc.Name}"/>
CRM </apex:column>
<apex:inputField value="{!acc.AccountNumber}"/>
</apex:column>
<apex:inputField value="{!acc.Type}"/>
</apex:column>
<apex:column headerValue="Industry">
<apex:inputField value="{!acc.Industry}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons >
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Example :
<apex:page Controller="AddmultipleAccountsController">
<apex:form >
<apex:pageBlock >
<apex:inputField value="{!acc.Name}"/>
CRM </apex:column>
<apex:inputField value="{!acc.AccountNumber}"/>
</apex:column>
<apex:inputField value="{!acc.Type}"/>
</apex:column>
<apex:column headerValue="Industry">
<apex:inputField value="{!acc.Industry}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons >
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
• public class AddmultipleAccountsController {
• listAccount.add(account);
• }
• listAccount.add(acc);
• }
• insert listAccount;
• }
• }
• }
•
• DataTable:
SALESFORCE
• No need to write inside pageblock or
CRM pageblocksection.
• There is no required value.
• The data can be displayed using custom style
sheets.
• we need to specify column headers explicitly.
• Visualforce page:
<apex:page controller="sample" sidebar="false" >
SALESFORCE <style type="text/css">
CRM .outBorder
{
border:3px outset black;
}
.inBorder
{
border-top:3px dotted black;
border-left:3px dotted black;
}
</style>
<apex:pageBlock title="Pageblock Table">
<apex:pageblockTable value="{!acc}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Name}"/>
</apex:pageblockTable>
• <apex:pageBlock title="Data Table">
<apex:dataTable value="{!acc}" var="a"
styleClass="outBorder" width="550px">
<apex:column styleClass="inBorder">
SALESFORCE <apex:facet name="header">Account
CRM Name</apex:facet>
<apex:outputText
>{!a.Name}</apex:outputText>
</apex:column>
<apex:column styleClass="inBorder">
<apex:facet name="header">Account
Number</apex:facet>
<apex:outputText
>{!a.AccountNumber}</apex:outputText>
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:page>
• Apex Controller:
}
• What is Apex Class?
Demo.Name
to Access Email we need create the object.
• <apex:outputpanel id="outptpnl">
• <apex:outputText value="click here"/>
• <apex:actionSupport event="onclick"
action="{!controllerMethodName}" rerender="pgblck"
/>
• Here action support adds AJAX to output panel,
so once you click on output panel controller method
SALESFORCE willbe called.
CRM •
• 3. Action function cannot add AJAX support to
another component. But from a particular
component which has AJAX support(onclick, onblur
etc) action function can be called to call the controller
method.
• Example:
• <apex:actionFunction name="myactionfun"
action="{!actionFunMethod}" reRender="outptText"/>
SALESFORCE <apex:inputcheckbox onclick="myJavaMethod()" />
CRM <script>
function myJavaMethod(){
myactionfun();// this call the action function
}
</script>
• <apex:actionFunction name="myactionfun"
action="{!actionFunMethod}" reRender="outptText"/>
SALESFORCE <apex:inputcheckbox onclick="myJavaMethod()" />
CRM <script>
function myJavaMethod(){
myactionfun();// this call the action function
}
</script>
Reference :
https://www.cloudforce4u.com/2013/06/difference-be
tween-action-support-and.html
Deployment Tools :
Different Deployment Methods
1. Change Sets
SALESFORCE
2. Eclipse with Force.com IDE
CRM
3. Force.com Migration Tool – ANT/Java based
Change Sets
The easiest way to send configuration changes from
one Salesforce organization to another is to use a
change set though it has a limitation that we can use it
among connected Salesforce orgs only (like Developer
Sandbox to Test Sandbox & Test Sandbox to
Production Org etc). We cannot use it in between any
individual Salesforce orgs.
To use change sets we need to have two
Salesforce org’s i.e. one Production org and its Sandbox org.
SALESFORCE
CRM Production Org:
It is Salesforce org with live data which is being actively used.
Sandbox:
A sandbox is a copy of your production organization. Sandboxes
contain the same metadata as production organization.
http://www.infallibletechie.com/2014/07/salesforce-components-
names-for-ant-tool.html
SALESFORCE
CRM
Test Class :
At least 75% of your Apex code must be covered by unit tests, and
all of those tests must complete successfully. But this should not
be our focus. We should aim for 100% code coverage, which
SALESFORCE ensures that you cover each positive and negative use case of your
code to cover and test each and every branch of your code.
CRM
Calls to System.debug are not counted as part of Apex code
coverage.
Test methods and test classes are not counted as part of Apex
code limit. So, no worries about writing long test class with more
methods just to make sure that all your code branches are
covered.
Every trigger you are trying to deploy should have at least 1%
coverage, but yes overall coverage of your production org after
getting your code deployed should be 75%, otherwise Salesforce
won’t let you deploy your code.
SALESFORCE
CRM Class can be deployed on 0% coverage as well, but as I told in last
point, that overall coverage of your production org after getting
your code deployed should be 75%, otherwise Salesforce won’t let
you deploy your code.
Class can be deployed on 0% coverage as well, but as I told in last
point, that overall coverage of your production org after getting
your code deployed should be 75%, otherwise Salesforce won’t let
you deploy your code.
SALESFORCE
CRM The key points while writing a test class are:
You have to start your class with @isTest annotation, then only
Salesforce will consider this class as test class.
Keep your class as Private, and the best practice is to name your
test class as your original Class or trigger Name + ‘Test’.
Methods of your test class have to be static, void and testMethod
keyword has to be used.
Prepare your test data which needs to be existing before your
actual test runs. There are multiple techniques of creating test data
now a days, for example, setup method, static resources etc. For
more details about @testsetup method check below link
@testSetup method in apex test class
Use Test.startTest() and Test.stopTest() to make sure that the actual
testing of your code happens with the fresh set of governer limits.
These methods help you to reset your governor limits just before
your actual code of testing get executed.
SALESFORCE req.setEndpoint('callout:My_Named_Credential/some_p
CRM ath');
Code Without Named Credentials :
HttpRequest req = new HttpRequest();
req.setEndpoint('https://my_endpoint.example.com/so
SALESFORCE me_path');
CRM
// - The header and header information
String username = 'myname';
String password = 'mypwd';
SALESFORCE Blob headerValue = Blob.valueOf(username + ':' + password);
CRM
Salesforce Integration
Make Callouts to External Services from Apex
• An Apex callout enables you to tightly integrate your Apex code
with an external service. The callout makes a call to an external
SALESFORCE web service or sends an HTTP request from Apex code, and then
CRM receives the response.
• Apex callouts come in two flavors.
• Web service callouts to SOAP web services use XML, and
typically require a WSDL document for code generation.
• HTTP callouts to services typically use REST with JSON.
• These two types of callouts are similar in terms of sending a
request to a service and receiving a response. But while
WSDL-based callouts apply to SOAP Web services, HTTP
callouts can be used with any HTTP service, either SOAP or
REST.
Salesforce Integration
Rest Vs Soap
The following are the differences between SOAP and REST API:
1.REST API has no has no official standard at all because it is an
SALESFORCE architectural style. SOAP API, on the other hand,has an official
CRM standard because it is a protocol.
2. REST APIs uses multiple standards like HTTP, JSON, URL, and
XML while SOAP APIs is largely based on HTTP and XML.
3. As REST API deploys multiple standards, so it takes fewer
resources and bandwidth as compared to SOAP that uses XML for
the creation of Payload and results in the large sized file.
4. The ways both APIs exposes the business logics are
also different. REST API takes advantage of URL
exposure like @path("/WeatherService") while SOAP API
use of services interfaces like @WebService.
Salesforce Integration
Rest Vs Soap
5. SOAP API defines too many standards, and its implementer
implements the things in a standard way only. In the case of
SALESFORCE miscommunication from service, the result will be the error. REST
CRM API, on the other hand, don't make emphasis on too many
standards and results in corrupt API in the end.
6. REST API uses Web Application Description Language, and
SOAP API used Web Services Description language for describing
the functionalities being offered by web services.
7.REST APIs are more convenient with JavaScript and can be
implemented easily as well. SOAP APIs are also convenient with
JavaScript but don't support for greater implementation.
Workbench API:
/services/data/v45.0/sobjects/account
}
REST “GET”
Http http = new Http();
HttpRequest request = new HttpRequest();
SALESFORCE request.setEndpoint('https://th-apex-http-callout.herokuapp.com/
CRM animals');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
// Deserialize the JSON string into collections of primitive data
types.
Map<String, Object> results = (Map<String, Object>)
JSON.deserializeUntyped(response.getBody());
// Cast the values in the 'animals' key as a list
List<Object> animals = (List<Object>)
SALESFORCE results.get('animals');
CRM System.debug('Received the following
animals:');
for (Object animal: animals) {
System.debug(animal);
}
}
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://th-apex-http-callo
SALESFORCE ut.herokuapp.com/animals');
CRM
request.setMethod('POST');
request.setHeader('Content-Type',
'application/json;charset=UTF-8');
// Set the body as a JSON object
request.setBody('{"name":"mighty moose"}');
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
SALESFORCE System.debug('The status code returned was
CRM not expected: ' +
response.getStatusCode() + ' ' +
response.getStatus());
} else {
System.debug(response.getBody());
}
Salesforce provides a WSDL (Web Service
Description Language) files. They are called
“Enterprise WSDL” and “Partner WSDL”. The
SALESFORCE WSDL is used by developers to aid in the
CRM creation of Salesforce integration pieces. A
typical process involves using the
Development Environment (eg, Eclipse for
Java, or Visual Studio for .Net) to consume the
WSDL, and generate classes which are then
referenced in the integration.
Enterprise WSDL:
SALESFORCE
CRM HTTP Method Description
One of the best ways to learn all the tags is by looking at the
Component
Convert VF page to lightning :
lightningStyleSheets="true"
SALESFORCE
CRM <apex:stylesheet
value="{!URLFOR($Resource.SLDS213,
'assets/styles/salesforce-lightning-design-system-
vf.css')}" />
<div class="slds myns">
<!-- the rest of your VF code goes here -->
</div>
Usage of Salesforce Optimizer: