SlideShare a Scribd company logo
1 of 64
Download to read offline
Apex Workshop for Admins
Salesforce WIT Trichy, India
Salesforce WIT Paris, France
June, 12th 2021
2.30PM (India)
11.00AM (France)
Bavadharani Ganesan
Salesforce Business system analyst
Trichy Women in Tech Group Leader
Doria Hamelryk
Salesforce Solution Architect
Paris Women in Tech Group Leader - MVP
Yosra Saidani
Salesforce Application&System Architect
Paris Women in Tech Group Leader
Yamini Kaapalle
Salesforce Technical Lead
Sarah Chalak
Salesforce Solution Architect
Thierry TROUIN
Technical Expert
Toulouse, France Group Leader
Salesforce MVP
Samuel Rajan
Salesforce Developer
Julie Boncour
Salesforce Solution Architect
Nantes, France Group Leader
Golden Hoodie
Fabrice Challier
Salesforce Technical Lead
Insa Badji
Salesforce Developer
Érica Baggi
Salesforce Developer
Erika McEvilly
Associate Software Engineer
You don’t have an org?
Use this link to create a new one: http://bit.ly/mysforg
Code resources :
All exercices available at: http://bit.ly/apexworkshopwit
1st Part Query Editor
2nd Part Apex Anonymous
3rd Part Apex Triggers
4th Part Code optimization
AGENDA
Query Editor
As an administrator, I need to be able to identify Leads from California,
without using a new List View or Report.
Use case : find records
Use case : find records with Query Editor
Use case : find records with Query Editor
Use case : find records with Query Editor
Use case : find records with Query Editor
Use case : find records with Query Editor
SOQL.txt
Exercice 1
Use case : find records with Query Editor
Use case : find records with Query Editor
SOQL.txt
Exercice 2
As an administrator, I need to be able to change the Company of the
records retrieved through the Query Editor
Use case : modify records
Use case : modify records with Query Editor
SOQL.txt
Exercice 3
Use case : modify records with Query Editor
Use case : modify records with Query Editor
Apex anonymous
As an administrator, I need to be able to create quickly Leads Test data.
Use case : Test Data creation
Introduction to Loops
This is a LIST
This is an INSTANCE
The LIST and the INSTANCE
are of the Type “Rose”
The LIST can be
decompose in several
INSTANCES
Each instance will have an
index representing its
position in the LIST
3
1
5
2
8
4
6 17
9
12
10
11
1 2 3
4 5 6
7 8 9
10 11 12
3
1
5
2
8
4
6 17
9
12
10
11
Going from one instance to the next one
in a LIST is what we call “iterate”.
An iteration is done with a LOOP
Introduction to FOR loops
Rose myFirstRose = new Rose (color='Red');
Rose mySecondRose = new Rose (color='Red');
...
List <Rose> myBouquet = new List <Rose> {myFirstRose, mySecondRose, ...};
For (Rose oneRose : myBouquet){
//do something with my oneRose
// do this until there is no rose left in myBouquet
}
Create the bouquet
Do something with each
rose in the bouquet
Use case : Test Data creation
Use case : Test Data creation
List<Lead> : myLeads
Lead : aDev
=> myLeads[0]
Lead : anAdmin
=> myLeads[1]
Lead : aUser
=> myLeads[2]
Next Lead exists? Loop !
Next Lead exists? Loop !
Next Lead exists?
Nop! Exit !
Anonymous.txt
Exercice 1
Use case : Test Data creation
Use case : Test Data creation
Use case : Test Data creation
Ctrl+E
to reopen your
last script
Anonymous.txt
Exercice 2
Use case : Test Data creation
As an administrator, I need to be able to create Test data for my Leads,
in a batch mode.
Use case : Test Data creation in Batch mode
Use case : Test Data creation in Batch mode
Anonymous.txt
Exercice 3
Use case : Test Data creation in Batch mode
As an administrator, I need to be able to replace all Leads having « CA » as
state by « California »
Use case : Update records with Apex Anonymous
Use case : Update records with Apex Anonymous
Anonymous.txt
Exercice 4
Use case : Update records with Apex Anonymous
Lead 1 administrator
Lead 2 administrator
Lead 3 developer
Lead 4 administrator
Lead 5 user
LastName
=
administrator?
List : UpdatedLeads
Lead 1 futureDeveloper
Lead 2 futureDeveloper
Lead 4 futureDeveloper
LEAD OBJECT
Lead 1 futureDeveloper
Lead 2 futureDeveloper
Lead 3 developer
Lead 4 futureDeveloper
Lead 5 user
Update
List : Query Results
Use case : Update records with Apex Anonymous
Anonymous.txt
Exercice 5
Use case : Update records with Apex Anonymous
Lead 1 administrator
Lead 2 administrator
Lead 4 administrator
Replace
LastName
List : Query Results
Lead 1 futureDeveloper
Lead 2 futureDeveloper
Lead 4 futureDeveloper
LEAD OBJECT
Lead 1 futureDeveloper
Lead 2 futureDeveloper
Lead 3 developer
Lead 4 futureDeveloper
Lead 5 user
Update
List : Query Results
Use case : Update records with Apex Anonymous
Apex Triggers
Saving Records : automation order
Old Record
New Record
See also : https://sforce.co/3ghaFVy
Notion of Trigger.Old and Trigger.New
Old Values (Trigger.Old) New Values (Trigger.New)
Create Record
Update Record
Delete Record
Notion of LIST
List<Lead> myLeads = [Select id,LastName from Lead];
for(Lead leadRecord : myLeads){
// Loop in Records
}
Index Value
0 Lead {Id:00Q8A000005InhUUAS,LastName:James}
1 Lead {Id:00Q8A000005InhTUAS,LastName:Feager}
2 Lead {Id:00Q8A000005InhbUAC,LastName:Cotton}
myLeads
LeadRecord #1
LeadRecord #2
LeadRecord #3
leadRecord #1 = myLeads[0];
Notion of MAP
Map<Id,Lead> myLeads = new Map <Id,Lead>{[Select id,FirstName,LastName from Lead]};
for(Lead leadRecord : myLeads.values()){
// Loop in Records
}
Key Value
00Q8A000005InhUUAS Lead {Id:00Q8A000005InhUUAS,LastName:James}
00Q8A000005InhTUAS Lead {Id:00Q8A000005InhTUAS,LastName:Feager}
00Q8A000005InhbUAC Lead {Id:00Q8A000005InhbUAC,LastName:Cotton}
myLeads
LeadRecord #1
LeadRecord #2
LeadRecord #3
leadRecord #1 = myLeads.get('00Q8A000005InhUUAS');
As a developer, I need the display the old and the new values of my Record
with the Debug Logs.
Use case : display new & old values
Create a new Trigger
Use of LIST in Triggers : Trigger.new
trigger LeadTrigger on Lead (before insert,before update) {
//Trigger.new = 1 or several Records with the new values - Used for creation and update
for(Lead rec : Trigger.new){
System.debug('new LastName >>'+rec.LastName);
}
}
Trigger.txt
Exercice 1.1
Use of LIST in Triggers : Trigger.old
trigger LeadTrigger on Lead (before insert,before update) {
//Trigger.new = 1 or several Records with the new values - Used for creation and update
for(Lead rec : Trigger.new){
System.debug('new LastName >>'+rec.LastName);
}
//Trigger.old = 1 or several Records with the old values - Used for update and delete
if(Trigger.old!=null) //check if we are in an update or delete event
for(Lead rec : Trigger.old){
System.debug('old LastName >>'+rec.LastName);
}
else System.debug('Trigger.old is null');
}
Trigger.txt
Exercice 1.2
Use of MAP in Triggers
trigger LeadTrigger on Lead (before insert,before update) {
//Trigger.new = 1 or several Records with the new values - Used for creation and update
for(Lead rec : Trigger.new){
System.debug('new LastName >>'+rec.LastName);
}
//Trigger.old = 1 or several Records with the old values - Used for update and delete
if(Trigger.old!=null) //check if we are in an update or delete event
for(Lead rec : Trigger.old){
System.debug('old LastName >>'+rec.LastName);
}
else System.debug('Trigger.old is null');
system.debug('oldMap contains : ');
for(String idOldRecord : Trigger.oldMap.keyset()){
system.debug('id : '+idOldRecord+'--- LastName : '+Trigger.oldMap.get(idOldRecord).LastName+')');
}
}
Trigger.txt
Exercice 1.3
As a developer, I need the Lead LastName to be saved in uppercase.
Use case : set the LastName to uppercase
Use case : set the LastName to uppercase
trigger LeadTrigger on Lead (before insert,before update) {
//Trigger.new = 1 or several Records with the new values
for(Lead rec : Trigger.new){ //for creations and updates
rec.LastName = rec.LastName.toUppercase();
}
//No need to update the record – new values will be commited to the database.
}
Trigger.txt
Exercice 2
Code Optimization
Remember : Trailhead is your best friend !
To access the Trailhead module : https://sforce.co/3ggvsbR
Create a new Class
Create a new Class
public class LeadHandler {
}
public class LeadHandler {
public static void upperCaseName(List<Lead> myLeads){
// TODO #2: make a Loop on the list leads, store the record in a variable named LeadRecord
for(Lead leadRecord : myLeads){
// TODO #3: assign to the field LastName the same value, in uppercase
leadRecord.LastName = leadRecord.LastName.toUppercase();
}
}
}
Trigger.txt
Exercice 3.1
trigger LeadTrigger on Lead(before insert,before update) {
//Trigger.new = 1 or several Records with the new values
LeadHandler.upperCaseName(Trigger.new); //call new method created
//No need to update the record – new values will be commited to the database.
}
Call the method from the Trigger
Trigger.txt
Exercice 3.2
As a developer, I need to split the behaviour of the Trigger between the
« Before Insert » and the « Before Update »
Use case : set the LastName to uppercase
Trigger
Before
Insert Update
After
Insert Update
trigger LeadTrigger on Lead (before insert,before update) {
if (trigger.isBefore) {
if(trigger.isUpdate){ // we want to manage the update with a ISCHANGED like
} else if (trigger.isInsert){ // will always be executed
}
}
}
Put the basic logic
Trigger.txt
Exercice 3.3
trigger LeadTrigger on Lead (before insert,before update) {
if (trigger.isBefore) {
if(trigger.isUpdate){ // we want to manage the update with a ISCHANGED like
} else if (trigger.isInsert){ // will always be executed
LeadHandler.upperCaseName(Trigger.new);
}
}
}
Call the method from the Trigger (insert)
Trigger.txt
Exercice 3.4
trigger LeadTrigger on Lead (before insert,before update) {
if (trigger.isBefore) {
if(trigger.isUpdate){ // we want to manage the update with a ISCHANGED like
List<Lead> leadToReallyUpdate = new List<Lead>();
for(Lead record : Trigger.new){
Lead oldRecord = Trigger.oldMap.get(record.Id);
if(record.LastName!=oldRecord.LastName){ // check if ISCHANGED
leadToReallyUpdate.add(record);
}
}
if(leadToReallyUpdate.size()>0) LeadHandler.upperCaseName(leadToReallyUpdate);
} else if (trigger.isInsert){
LeadHandler.upperCaseName(Trigger.new);
}
}
Call the method from the Trigger (update)
Trigger.txt
Exercice 3.5
Erica Erika Fabrice Insa Julie
Samuel Sarah Thierry Yamini Yosra
Bavadharani Doria

More Related Content

What's hot

Reactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NETReactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NETEPAM
 
JFokus 50 new things with java 8
JFokus 50 new things with java 8JFokus 50 new things with java 8
JFokus 50 new things with java 8José Paumard
 
R Programming: Introduction To R Packages
R Programming: Introduction To R PackagesR Programming: Introduction To R Packages
R Programming: Introduction To R PackagesRsquared Academy
 
The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30Mahmoud Samir Fayed
 
Not All PHP Implementations Are Equally Useful
Not All PHP Implementations Are Equally UsefulNot All PHP Implementations Are Equally Useful
Not All PHP Implementations Are Equally UsefulPositive Hack Days
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentSheeju Alex
 
SPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeSPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeAdriel Café
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroidSavvycom Savvycom
 
Integration test framework
Integration test frameworkIntegration test framework
Integration test frameworkIlya Medvedev
 
Data Structure Lecture 7
Data Structure Lecture 7Data Structure Lecture 7
Data Structure Lecture 7Teksify
 
The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185Mahmoud Samir Fayed
 
Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹Kros Huang
 
Rxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaRxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaKros Huang
 
Parallel-Ready Java Code: Managing Mutation in an Imperative Language
Parallel-Ready Java Code: Managing Mutation in an Imperative LanguageParallel-Ready Java Code: Managing Mutation in an Imperative Language
Parallel-Ready Java Code: Managing Mutation in an Imperative LanguageMaurice Naftalin
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTDavid Chandler
 

What's hot (19)

Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
 
Reactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NETReactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NET
 
JFokus 50 new things with java 8
JFokus 50 new things with java 8JFokus 50 new things with java 8
JFokus 50 new things with java 8
 
R Programming: Introduction To R Packages
R Programming: Introduction To R PackagesR Programming: Introduction To R Packages
R Programming: Introduction To R Packages
 
The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30
 
Not All PHP Implementations Are Equally Useful
Not All PHP Implementations Are Equally UsefulNot All PHP Implementations Are Equally Useful
Not All PHP Implementations Are Equally Useful
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
SPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeSPARQL-DL - Theory & Practice
SPARQL-DL - Theory & Practice
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroid
 
Integration test framework
Integration test frameworkIntegration test framework
Integration test framework
 
Data Structure Lecture 7
Data Structure Lecture 7Data Structure Lecture 7
Data Structure Lecture 7
 
The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185
 
Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹
 
Tdd
TddTdd
Tdd
 
Java Week3(A) Notepad
Java Week3(A)   NotepadJava Week3(A)   Notepad
Java Week3(A) Notepad
 
Rxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaRxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJava
 
Servlet Filters
Servlet FiltersServlet Filters
Servlet Filters
 
Parallel-Ready Java Code: Managing Mutation in an Imperative Language
Parallel-Ready Java Code: Managing Mutation in an Imperative LanguageParallel-Ready Java Code: Managing Mutation in an Imperative Language
Parallel-Ready Java Code: Managing Mutation in an Imperative Language
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWT
 

Similar to Apex for Admins Workshop

Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Codemotion
 
The Ring programming language version 1.7 book - Part 12 of 196
The Ring programming language version 1.7 book - Part 12 of 196The Ring programming language version 1.7 book - Part 12 of 196
The Ring programming language version 1.7 book - Part 12 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 79 of 185
The Ring programming language version 1.5.4 book - Part 79 of 185The Ring programming language version 1.5.4 book - Part 79 of 185
The Ring programming language version 1.5.4 book - Part 79 of 185Mahmoud Samir Fayed
 
03-inheritance.ppt
03-inheritance.ppt03-inheritance.ppt
03-inheritance.pptSaiM947604
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxfestockton
 
Testing in Laravel
Testing in LaravelTesting in Laravel
Testing in LaravelAhmed Yahia
 
The Ring programming language version 1.5.4 book - Part 78 of 185
The Ring programming language version 1.5.4 book - Part 78 of 185The Ring programming language version 1.5.4 book - Part 78 of 185
The Ring programming language version 1.5.4 book - Part 78 of 185Mahmoud Samir Fayed
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packagesAjay Ohri
 
The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181Mahmoud Samir Fayed
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectJonathan Wage
 

Similar to Apex for Admins Workshop (20)

Lazy Java
Lazy JavaLazy Java
Lazy Java
 
Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018
 
Lazy java
Lazy javaLazy java
Lazy java
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
 
The Ring programming language version 1.7 book - Part 12 of 196
The Ring programming language version 1.7 book - Part 12 of 196The Ring programming language version 1.7 book - Part 12 of 196
The Ring programming language version 1.7 book - Part 12 of 196
 
The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189
 
The Ring programming language version 1.5.4 book - Part 79 of 185
The Ring programming language version 1.5.4 book - Part 79 of 185The Ring programming language version 1.5.4 book - Part 79 of 185
The Ring programming language version 1.5.4 book - Part 79 of 185
 
03-inheritance.ppt
03-inheritance.ppt03-inheritance.ppt
03-inheritance.ppt
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
 
Testing in Laravel
Testing in LaravelTesting in Laravel
Testing in Laravel
 
The Ring programming language version 1.5.4 book - Part 78 of 185
The Ring programming language version 1.5.4 book - Part 78 of 185The Ring programming language version 1.5.4 book - Part 78 of 185
The Ring programming language version 1.5.4 book - Part 78 of 185
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
 
The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Applicative style programming
Applicative style programmingApplicative style programming
Applicative style programming
 
Core java
Core javaCore java
Core java
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine Project
 
Php tests tips
Php tests tipsPhp tests tips
Php tests tips
 

More from Doria Hamelryk

Salesforce Release Spring 24 - French Gathering
Salesforce Release Spring 24 - French GatheringSalesforce Release Spring 24 - French Gathering
Salesforce Release Spring 24 - French GatheringDoria Hamelryk
 
Concours Trailblazers be Certified
Concours Trailblazers be Certified Concours Trailblazers be Certified
Concours Trailblazers be Certified Doria Hamelryk
 
+10 of Our Favorite Salesforce Spring ’21 Features
+10 of Our Favorite Salesforce Spring ’21 Features+10 of Our Favorite Salesforce Spring ’21 Features
+10 of Our Favorite Salesforce Spring ’21 FeaturesDoria Hamelryk
 
Découverte d'Einstein Analytics (Tableau CRM)
Découverte d'Einstein Analytics (Tableau CRM)Découverte d'Einstein Analytics (Tableau CRM)
Découverte d'Einstein Analytics (Tableau CRM)Doria Hamelryk
 
Odaseva : un outil de gestion pour les règles RGPD
Odaseva : un outil de gestion pour les règles RGPDOdaseva : un outil de gestion pour les règles RGPD
Odaseva : un outil de gestion pour les règles RGPDDoria Hamelryk
 
Opportunity Management workshop
Opportunity Management workshopOpportunity Management workshop
Opportunity Management workshopDoria Hamelryk
 
A la découverte de pardot
A la découverte de pardotA la découverte de pardot
A la découverte de pardotDoria Hamelryk
 
Flows - what you should know before implementing
Flows - what you should know before implementingFlows - what you should know before implementing
Flows - what you should know before implementingDoria Hamelryk
 
Gérer ses campagnes marketing
Gérer ses campagnes marketingGérer ses campagnes marketing
Gérer ses campagnes marketingDoria Hamelryk
 
10 of Our Favorite Salesforce Winter ’21 Features
10 of Our Favorite Salesforce Winter ’21 Features10 of Our Favorite Salesforce Winter ’21 Features
10 of Our Favorite Salesforce Winter ’21 FeaturesDoria Hamelryk
 
Ecrire son premier Trigger (et les comprendre)
Ecrire son premier Trigger (et les comprendre)Ecrire son premier Trigger (et les comprendre)
Ecrire son premier Trigger (et les comprendre)Doria Hamelryk
 
Les formules et moi, ça fait 3!
Les formules et moi, ça fait 3!Les formules et moi, ça fait 3!
Les formules et moi, ça fait 3!Doria Hamelryk
 
Salesforce Import Tools
Salesforce Import ToolsSalesforce Import Tools
Salesforce Import ToolsDoria Hamelryk
 
Concours Ladies be Certified #sfpariswit
Concours Ladies be Certified #sfpariswitConcours Ladies be Certified #sfpariswit
Concours Ladies be Certified #sfpariswitDoria Hamelryk
 
Salesforce Starter Kit
Salesforce Starter KitSalesforce Starter Kit
Salesforce Starter KitDoria Hamelryk
 
Comment se préparer pour les certifications Salesforce
Comment se préparer pour les certifications SalesforceComment se préparer pour les certifications Salesforce
Comment se préparer pour les certifications SalesforceDoria Hamelryk
 
Comment l'automatisation dans Salesforce peut vous faciliter la vie
Comment l'automatisation dans Salesforce peut vous faciliter la vieComment l'automatisation dans Salesforce peut vous faciliter la vie
Comment l'automatisation dans Salesforce peut vous faciliter la vieDoria Hamelryk
 
Girls, What's Next? - Première rencontre du groupe
Girls, What's Next? - Première rencontre du groupeGirls, What's Next? - Première rencontre du groupe
Girls, What's Next? - Première rencontre du groupeDoria Hamelryk
 
Einstein Next Best Action - French Touch Dreamin 2019
Einstein Next Best Action - French Touch Dreamin 2019Einstein Next Best Action - French Touch Dreamin 2019
Einstein Next Best Action - French Touch Dreamin 2019Doria Hamelryk
 

More from Doria Hamelryk (20)

Salesforce Release Spring 24 - French Gathering
Salesforce Release Spring 24 - French GatheringSalesforce Release Spring 24 - French Gathering
Salesforce Release Spring 24 - French Gathering
 
Winter 22 release
Winter 22 releaseWinter 22 release
Winter 22 release
 
Concours Trailblazers be Certified
Concours Trailblazers be Certified Concours Trailblazers be Certified
Concours Trailblazers be Certified
 
+10 of Our Favorite Salesforce Spring ’21 Features
+10 of Our Favorite Salesforce Spring ’21 Features+10 of Our Favorite Salesforce Spring ’21 Features
+10 of Our Favorite Salesforce Spring ’21 Features
 
Découverte d'Einstein Analytics (Tableau CRM)
Découverte d'Einstein Analytics (Tableau CRM)Découverte d'Einstein Analytics (Tableau CRM)
Découverte d'Einstein Analytics (Tableau CRM)
 
Odaseva : un outil de gestion pour les règles RGPD
Odaseva : un outil de gestion pour les règles RGPDOdaseva : un outil de gestion pour les règles RGPD
Odaseva : un outil de gestion pour les règles RGPD
 
Opportunity Management workshop
Opportunity Management workshopOpportunity Management workshop
Opportunity Management workshop
 
A la découverte de pardot
A la découverte de pardotA la découverte de pardot
A la découverte de pardot
 
Flows - what you should know before implementing
Flows - what you should know before implementingFlows - what you should know before implementing
Flows - what you should know before implementing
 
Gérer ses campagnes marketing
Gérer ses campagnes marketingGérer ses campagnes marketing
Gérer ses campagnes marketing
 
10 of Our Favorite Salesforce Winter ’21 Features
10 of Our Favorite Salesforce Winter ’21 Features10 of Our Favorite Salesforce Winter ’21 Features
10 of Our Favorite Salesforce Winter ’21 Features
 
Ecrire son premier Trigger (et les comprendre)
Ecrire son premier Trigger (et les comprendre)Ecrire son premier Trigger (et les comprendre)
Ecrire son premier Trigger (et les comprendre)
 
Les formules et moi, ça fait 3!
Les formules et moi, ça fait 3!Les formules et moi, ça fait 3!
Les formules et moi, ça fait 3!
 
Salesforce Import Tools
Salesforce Import ToolsSalesforce Import Tools
Salesforce Import Tools
 
Concours Ladies be Certified #sfpariswit
Concours Ladies be Certified #sfpariswitConcours Ladies be Certified #sfpariswit
Concours Ladies be Certified #sfpariswit
 
Salesforce Starter Kit
Salesforce Starter KitSalesforce Starter Kit
Salesforce Starter Kit
 
Comment se préparer pour les certifications Salesforce
Comment se préparer pour les certifications SalesforceComment se préparer pour les certifications Salesforce
Comment se préparer pour les certifications Salesforce
 
Comment l'automatisation dans Salesforce peut vous faciliter la vie
Comment l'automatisation dans Salesforce peut vous faciliter la vieComment l'automatisation dans Salesforce peut vous faciliter la vie
Comment l'automatisation dans Salesforce peut vous faciliter la vie
 
Girls, What's Next? - Première rencontre du groupe
Girls, What's Next? - Première rencontre du groupeGirls, What's Next? - Première rencontre du groupe
Girls, What's Next? - Première rencontre du groupe
 
Einstein Next Best Action - French Touch Dreamin 2019
Einstein Next Best Action - French Touch Dreamin 2019Einstein Next Best Action - French Touch Dreamin 2019
Einstein Next Best Action - French Touch Dreamin 2019
 

Recently uploaded

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Apex for Admins Workshop

  • 1. Apex Workshop for Admins Salesforce WIT Trichy, India Salesforce WIT Paris, France June, 12th 2021 2.30PM (India) 11.00AM (France)
  • 2. Bavadharani Ganesan Salesforce Business system analyst Trichy Women in Tech Group Leader Doria Hamelryk Salesforce Solution Architect Paris Women in Tech Group Leader - MVP
  • 3. Yosra Saidani Salesforce Application&System Architect Paris Women in Tech Group Leader Yamini Kaapalle Salesforce Technical Lead
  • 4. Sarah Chalak Salesforce Solution Architect Thierry TROUIN Technical Expert Toulouse, France Group Leader Salesforce MVP
  • 5. Samuel Rajan Salesforce Developer Julie Boncour Salesforce Solution Architect Nantes, France Group Leader Golden Hoodie
  • 6. Fabrice Challier Salesforce Technical Lead Insa Badji Salesforce Developer
  • 7. Érica Baggi Salesforce Developer Erika McEvilly Associate Software Engineer
  • 8. You don’t have an org? Use this link to create a new one: http://bit.ly/mysforg Code resources : All exercices available at: http://bit.ly/apexworkshopwit
  • 9. 1st Part Query Editor 2nd Part Apex Anonymous 3rd Part Apex Triggers 4th Part Code optimization AGENDA
  • 11. As an administrator, I need to be able to identify Leads from California, without using a new List View or Report. Use case : find records
  • 12. Use case : find records with Query Editor
  • 13. Use case : find records with Query Editor
  • 14. Use case : find records with Query Editor
  • 15. Use case : find records with Query Editor
  • 16. Use case : find records with Query Editor SOQL.txt Exercice 1
  • 17. Use case : find records with Query Editor
  • 18. Use case : find records with Query Editor SOQL.txt Exercice 2
  • 19. As an administrator, I need to be able to change the Company of the records retrieved through the Query Editor Use case : modify records
  • 20. Use case : modify records with Query Editor SOQL.txt Exercice 3
  • 21. Use case : modify records with Query Editor
  • 22. Use case : modify records with Query Editor
  • 24. As an administrator, I need to be able to create quickly Leads Test data. Use case : Test Data creation
  • 25. Introduction to Loops This is a LIST This is an INSTANCE The LIST and the INSTANCE are of the Type “Rose” The LIST can be decompose in several INSTANCES Each instance will have an index representing its position in the LIST 3 1 5 2 8 4 6 17 9 12 10 11 1 2 3 4 5 6 7 8 9 10 11 12 3 1 5 2 8 4 6 17 9 12 10 11 Going from one instance to the next one in a LIST is what we call “iterate”. An iteration is done with a LOOP
  • 26. Introduction to FOR loops Rose myFirstRose = new Rose (color='Red'); Rose mySecondRose = new Rose (color='Red'); ... List <Rose> myBouquet = new List <Rose> {myFirstRose, mySecondRose, ...}; For (Rose oneRose : myBouquet){ //do something with my oneRose // do this until there is no rose left in myBouquet } Create the bouquet Do something with each rose in the bouquet
  • 27. Use case : Test Data creation
  • 28. Use case : Test Data creation List<Lead> : myLeads Lead : aDev => myLeads[0] Lead : anAdmin => myLeads[1] Lead : aUser => myLeads[2] Next Lead exists? Loop ! Next Lead exists? Loop ! Next Lead exists? Nop! Exit ! Anonymous.txt Exercice 1
  • 29. Use case : Test Data creation
  • 30. Use case : Test Data creation
  • 31. Use case : Test Data creation Ctrl+E to reopen your last script Anonymous.txt Exercice 2
  • 32. Use case : Test Data creation
  • 33. As an administrator, I need to be able to create Test data for my Leads, in a batch mode. Use case : Test Data creation in Batch mode
  • 34. Use case : Test Data creation in Batch mode Anonymous.txt Exercice 3
  • 35. Use case : Test Data creation in Batch mode
  • 36. As an administrator, I need to be able to replace all Leads having « CA » as state by « California » Use case : Update records with Apex Anonymous
  • 37. Use case : Update records with Apex Anonymous Anonymous.txt Exercice 4
  • 38. Use case : Update records with Apex Anonymous Lead 1 administrator Lead 2 administrator Lead 3 developer Lead 4 administrator Lead 5 user LastName = administrator? List : UpdatedLeads Lead 1 futureDeveloper Lead 2 futureDeveloper Lead 4 futureDeveloper LEAD OBJECT Lead 1 futureDeveloper Lead 2 futureDeveloper Lead 3 developer Lead 4 futureDeveloper Lead 5 user Update List : Query Results
  • 39. Use case : Update records with Apex Anonymous Anonymous.txt Exercice 5
  • 40. Use case : Update records with Apex Anonymous Lead 1 administrator Lead 2 administrator Lead 4 administrator Replace LastName List : Query Results Lead 1 futureDeveloper Lead 2 futureDeveloper Lead 4 futureDeveloper LEAD OBJECT Lead 1 futureDeveloper Lead 2 futureDeveloper Lead 3 developer Lead 4 futureDeveloper Lead 5 user Update List : Query Results
  • 41. Use case : Update records with Apex Anonymous
  • 43. Saving Records : automation order Old Record New Record See also : https://sforce.co/3ghaFVy
  • 44. Notion of Trigger.Old and Trigger.New Old Values (Trigger.Old) New Values (Trigger.New) Create Record Update Record Delete Record
  • 45. Notion of LIST List<Lead> myLeads = [Select id,LastName from Lead]; for(Lead leadRecord : myLeads){ // Loop in Records } Index Value 0 Lead {Id:00Q8A000005InhUUAS,LastName:James} 1 Lead {Id:00Q8A000005InhTUAS,LastName:Feager} 2 Lead {Id:00Q8A000005InhbUAC,LastName:Cotton} myLeads LeadRecord #1 LeadRecord #2 LeadRecord #3 leadRecord #1 = myLeads[0];
  • 46. Notion of MAP Map<Id,Lead> myLeads = new Map <Id,Lead>{[Select id,FirstName,LastName from Lead]}; for(Lead leadRecord : myLeads.values()){ // Loop in Records } Key Value 00Q8A000005InhUUAS Lead {Id:00Q8A000005InhUUAS,LastName:James} 00Q8A000005InhTUAS Lead {Id:00Q8A000005InhTUAS,LastName:Feager} 00Q8A000005InhbUAC Lead {Id:00Q8A000005InhbUAC,LastName:Cotton} myLeads LeadRecord #1 LeadRecord #2 LeadRecord #3 leadRecord #1 = myLeads.get('00Q8A000005InhUUAS');
  • 47. As a developer, I need the display the old and the new values of my Record with the Debug Logs. Use case : display new & old values
  • 48. Create a new Trigger
  • 49. Use of LIST in Triggers : Trigger.new trigger LeadTrigger on Lead (before insert,before update) { //Trigger.new = 1 or several Records with the new values - Used for creation and update for(Lead rec : Trigger.new){ System.debug('new LastName >>'+rec.LastName); } } Trigger.txt Exercice 1.1
  • 50. Use of LIST in Triggers : Trigger.old trigger LeadTrigger on Lead (before insert,before update) { //Trigger.new = 1 or several Records with the new values - Used for creation and update for(Lead rec : Trigger.new){ System.debug('new LastName >>'+rec.LastName); } //Trigger.old = 1 or several Records with the old values - Used for update and delete if(Trigger.old!=null) //check if we are in an update or delete event for(Lead rec : Trigger.old){ System.debug('old LastName >>'+rec.LastName); } else System.debug('Trigger.old is null'); } Trigger.txt Exercice 1.2
  • 51. Use of MAP in Triggers trigger LeadTrigger on Lead (before insert,before update) { //Trigger.new = 1 or several Records with the new values - Used for creation and update for(Lead rec : Trigger.new){ System.debug('new LastName >>'+rec.LastName); } //Trigger.old = 1 or several Records with the old values - Used for update and delete if(Trigger.old!=null) //check if we are in an update or delete event for(Lead rec : Trigger.old){ System.debug('old LastName >>'+rec.LastName); } else System.debug('Trigger.old is null'); system.debug('oldMap contains : '); for(String idOldRecord : Trigger.oldMap.keyset()){ system.debug('id : '+idOldRecord+'--- LastName : '+Trigger.oldMap.get(idOldRecord).LastName+')'); } } Trigger.txt Exercice 1.3
  • 52. As a developer, I need the Lead LastName to be saved in uppercase. Use case : set the LastName to uppercase
  • 53. Use case : set the LastName to uppercase trigger LeadTrigger on Lead (before insert,before update) { //Trigger.new = 1 or several Records with the new values for(Lead rec : Trigger.new){ //for creations and updates rec.LastName = rec.LastName.toUppercase(); } //No need to update the record – new values will be commited to the database. } Trigger.txt Exercice 2
  • 55. Remember : Trailhead is your best friend ! To access the Trailhead module : https://sforce.co/3ggvsbR
  • 56. Create a new Class
  • 57. Create a new Class public class LeadHandler { } public class LeadHandler { public static void upperCaseName(List<Lead> myLeads){ // TODO #2: make a Loop on the list leads, store the record in a variable named LeadRecord for(Lead leadRecord : myLeads){ // TODO #3: assign to the field LastName the same value, in uppercase leadRecord.LastName = leadRecord.LastName.toUppercase(); } } } Trigger.txt Exercice 3.1
  • 58. trigger LeadTrigger on Lead(before insert,before update) { //Trigger.new = 1 or several Records with the new values LeadHandler.upperCaseName(Trigger.new); //call new method created //No need to update the record – new values will be commited to the database. } Call the method from the Trigger Trigger.txt Exercice 3.2
  • 59. As a developer, I need to split the behaviour of the Trigger between the « Before Insert » and the « Before Update » Use case : set the LastName to uppercase Trigger Before Insert Update After Insert Update
  • 60. trigger LeadTrigger on Lead (before insert,before update) { if (trigger.isBefore) { if(trigger.isUpdate){ // we want to manage the update with a ISCHANGED like } else if (trigger.isInsert){ // will always be executed } } } Put the basic logic Trigger.txt Exercice 3.3
  • 61. trigger LeadTrigger on Lead (before insert,before update) { if (trigger.isBefore) { if(trigger.isUpdate){ // we want to manage the update with a ISCHANGED like } else if (trigger.isInsert){ // will always be executed LeadHandler.upperCaseName(Trigger.new); } } } Call the method from the Trigger (insert) Trigger.txt Exercice 3.4
  • 62. trigger LeadTrigger on Lead (before insert,before update) { if (trigger.isBefore) { if(trigger.isUpdate){ // we want to manage the update with a ISCHANGED like List<Lead> leadToReallyUpdate = new List<Lead>(); for(Lead record : Trigger.new){ Lead oldRecord = Trigger.oldMap.get(record.Id); if(record.LastName!=oldRecord.LastName){ // check if ISCHANGED leadToReallyUpdate.add(record); } } if(leadToReallyUpdate.size()>0) LeadHandler.upperCaseName(leadToReallyUpdate); } else if (trigger.isInsert){ LeadHandler.upperCaseName(Trigger.new); } } Call the method from the Trigger (update) Trigger.txt Exercice 3.5
  • 63.
  • 64. Erica Erika Fabrice Insa Julie Samuel Sarah Thierry Yamini Yosra Bavadharani Doria