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

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
Positive Hack Days
 
Data Structure Lecture 7
Data Structure Lecture 7Data Structure Lecture 7
Data Structure Lecture 7
Teksify
 

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

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
festockton
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
Ajay Ohri
 
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine Project
Jonathan 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

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

Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 

Recently uploaded (20)

Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Navigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi DaparthiNavigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi Daparthi
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 

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