SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Triggers for Admins: A Five-step 
Framework for Creating Triggers 
(a play in 5 acts) 
Veronica Beck Ashima Saigal 
@gandhilover
Ashima Saigal 
Database Sherpa founder 
Summer 2014 MVP
Veronica Beck 
Bigger Boat Consulting Senior Consultant
Setting 
“We want our own custom campaign 
member statuses, but it’s a pain to 
have to add them every time we 
create a campaign.” – Celeste, yoga 
studio owner
Audience Participation 
We have some suggestions: 
● Breathe! You can do it. 
● Replace trepidation with curiosity. 
● Know this won’t happen overnight. 
● Remember, you are not alone.
Triggers for Admins 
Act 1: Where do I write code? 
Act 2: Gather Your Resources 
Act 3: Clarify Your Requirements 
Act 4: Code and Test 
Act 5: Finalize and Launch!
Act 1: Where do I write code? 
Developer Org: https://developer.salesforce.com/gettingstarted
Act 1: Where do I write code?
Act 1: Where do I write code? 
Go to Setup. 
Find the object where you want the trigger. 
Click on Triggers.
Act 1: Where do I write code? 
Click the New button, and voila!
Act 1: Where do I write code? 
Some other tools for writing code: 
• Salesforce Developer Console 
• Eclipse 
[there are many more!]
Act 2: Gather your resources 
● www.sfdc99.com 
● Creator David Liu presents: “Anyone 
can learn to code Apex!” On 
Wednesday at 11 am
Act 2: Gather your resources 
● Power of Us HUB (nonprofits) 
http://www.salesforcefoundation.org/help/power-of-us-hub/ 
● Success Community: (Salesforce online community) 
● Local User Groups (in person meetings) 
● Developer User Groups (in person meetings) 
● Network at Dreamforce!
Act 3: Clarify Requirements 
● What problem are you trying to solve? 
o Inconsistent campaign member statuses 
● What needs to happen? 
o Auto creation of desired member statuses 
● When does it need to happen? 
o When a new campaign is created 
● Should it always happen for all records? 
o Only for workshop type campaigns
Act 3: Clarify Requirements 
Write it “In English” (aka pseudo code): 
When a campaign is inserted 
● Check if it’s a workshop campaign 
● If it is a workshop campaign … 
o Get rid of the default Campaign Statuses 
o Add the following campaign statuses: 
 Invited (default) 
 Accepted (responded) 
 Attended (responded) 
 No Show
Act 4: Code and Test 
● Recap 
o Set up your coding environment 
o Go through some tutorials 
o Clarify what you’re trying to do 
● Get ready, set, go! 
● Search for code, copy and paste.
Act 4: Code and Test
Act 4: Code and Test
Act 4: Code and Test 
Design Pattern 1: Use Trigger.New 
Trigger.new contains all records that are being inserted or updated 
Loop through the trigger.new collection 
Do something with each record 
Code Sample: 
For (Campaign c : trigger.new){ // This is the beginning of the loop 
//do something with each record 
} //this is the end of the loop
Act 4: Code and Test
Act 4: Code and Test
Act 4: Code and Test
Act 4: Code and Test
Act 4: Code and Test
Act 4: Code and Test
Act 4: Code and Test
Act 4: Code and Test 
Design Pattern 2: Use Lists and Sets 
Lists and Sets are like a 
bucket to hold records for 
later processing
Act 4: Code and Test
Act 4: Code and Test
Act 4: Code and Test
Act 4: Code and Test
Act 4: Code and Test
Act 4: Code and Test 
Design Pattern 3: Inserts, Updates, Deletes Outside of Loops 
For (Campaign c : workshopCampaigns) { //start of the loop 
CampaignMemberStatus myCMS = ….. 
myStuff.add(myCMS); 
} // end of the loop 
Insert myStuff ; Insert is happening AFTER the loop
Act 4: Code and Test 
● Common design elements 
o Loop through trigger.new (or trigger.old) 
o Use collections to hold records to process 
o Do inserts, updates, and deletes outside of your loops 
● Other helpful Tips 
o Comment your code! 
o Use system.debug for troubleshooting
Act 5: Finalize and Launch 
• Ask users to test with real-life scenarios 
• Revise code, have users re-test 
• Write test methods 
– Sfdc99.com has examples and tutorial 
– Force.com Apex Developer Guide 
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm 
• Deploy! 
– Use Salesforce change sets and deployment connections in Setup area
That’s a Wrap
Begin Your Coding Journey Today! 
● Set up your FREE developer account 
● Find a mentor – introduce yourself to at least three people and tell them 
you’re looking for help with coding. 
● Visit sfdc99.com. 
● Celebrate the beginning of your journey!
Resources 
Beginner Tutorial - http://www.sfdc99.com/beginner-tutorials/ 
Salesforce Developer Forum - https://developer.salesforce.com/forums/ 
Trigger Best Practices - http://www.iterativelogic.com/salesforce-apex-trigger-best-practices/ 
Trigger Order of Execution - 
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execu 
tion.htm 
Writing Bulk Triggers - http://blog.jeffdouglas.com/2009/04/20/writing-bulk-triggers-for-salesforce/ 
Force.com Apex Developer Guide - 
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm

Weitere ähnliche Inhalte

Was ist angesagt?

Shorten Your Development Time with an Extensible Design for Apex
Shorten Your Development Time with an Extensible Design for ApexShorten Your Development Time with an Extensible Design for Apex
Shorten Your Development Time with an Extensible Design for ApexSalesforce Developers
 
Leveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APILeveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APISalesforce Developers
 
Episode 12 - Basics of Trigger
Episode 12 - Basics of TriggerEpisode 12 - Basics of Trigger
Episode 12 - Basics of TriggerJitendra Zaa
 
DevOps - Agile on Steroids by Tom Clement Oketch and Augustine Kisitu
DevOps - Agile on Steroids by Tom Clement Oketch and Augustine KisituDevOps - Agile on Steroids by Tom Clement Oketch and Augustine Kisitu
DevOps - Agile on Steroids by Tom Clement Oketch and Augustine KisituThoughtworks
 
Adding value in an agile context
Adding value in an agile contextAdding value in an agile context
Adding value in an agile contextHouseofTest
 
Definition of Done and Product Backlog refinement
Definition of Done and Product Backlog refinementDefinition of Done and Product Backlog refinement
Definition of Done and Product Backlog refinementChristian Vos
 
Performance Testing Workshop at CzechTest2016 – SmartMeter.io
Performance Testing Workshop at CzechTest2016 – SmartMeter.ioPerformance Testing Workshop at CzechTest2016 – SmartMeter.io
Performance Testing Workshop at CzechTest2016 – SmartMeter.ioSmartMeter.io
 
Simplify Salesforce Testing with AI-Driven Codeless Tools
Simplify Salesforce Testing with AI-Driven Codeless ToolsSimplify Salesforce Testing with AI-Driven Codeless Tools
Simplify Salesforce Testing with AI-Driven Codeless ToolsSauce Labs
 
Role of Automation in Testing
Role of Automation in TestingRole of Automation in Testing
Role of Automation in TestingAnand Bagmar
 
E-TAIL QA: Approach to E-commerce testing in an Agile environment
E-TAIL QA: Approach to E-commerce testing in an Agile environmentE-TAIL QA: Approach to E-commerce testing in an Agile environment
E-TAIL QA: Approach to E-commerce testing in an Agile environmentNurun
 
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...ATAGTR2017 Unified APM: The new age performance monitoring for production sys...
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...Agile Testing Alliance
 
Definition Of Done
Definition Of DoneDefinition Of Done
Definition Of DoneWei Zhu
 
Definition of done training
Definition of done trainingDefinition of done training
Definition of done trainingMonica Yap
 
Black Friday Is Approaching. Are You Prepared- Infographic
Black Friday Is Approaching. Are You Prepared- InfographicBlack Friday Is Approaching. Are You Prepared- Infographic
Black Friday Is Approaching. Are You Prepared- InfographicTestingXperts
 
Automating Web Analytics
Automating Web AnalyticsAutomating Web Analytics
Automating Web AnalyticsAnand Bagmar
 
Building Test Automations the agile way
Building Test Automations the agile way Building Test Automations the agile way
Building Test Automations the agile way MakeMyTrip.com
 
London SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingLondon SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingRichard Clark
 

Was ist angesagt? (20)

Shorten Your Development Time with an Extensible Design for Apex
Shorten Your Development Time with an Extensible Design for ApexShorten Your Development Time with an Extensible Design for Apex
Shorten Your Development Time with an Extensible Design for Apex
 
Leveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APILeveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk API
 
Episode 12 - Basics of Trigger
Episode 12 - Basics of TriggerEpisode 12 - Basics of Trigger
Episode 12 - Basics of Trigger
 
The Apex Ten Commandments
The Apex Ten CommandmentsThe Apex Ten Commandments
The Apex Ten Commandments
 
DevOps - Agile on Steroids by Tom Clement Oketch and Augustine Kisitu
DevOps - Agile on Steroids by Tom Clement Oketch and Augustine KisituDevOps - Agile on Steroids by Tom Clement Oketch and Augustine Kisitu
DevOps - Agile on Steroids by Tom Clement Oketch and Augustine Kisitu
 
Adding value in an agile context
Adding value in an agile contextAdding value in an agile context
Adding value in an agile context
 
Definition of Done and Product Backlog refinement
Definition of Done and Product Backlog refinementDefinition of Done and Product Backlog refinement
Definition of Done and Product Backlog refinement
 
Selenium at Salesforce Scale
Selenium at Salesforce ScaleSelenium at Salesforce Scale
Selenium at Salesforce Scale
 
Performance Testing Workshop at CzechTest2016 – SmartMeter.io
Performance Testing Workshop at CzechTest2016 – SmartMeter.ioPerformance Testing Workshop at CzechTest2016 – SmartMeter.io
Performance Testing Workshop at CzechTest2016 – SmartMeter.io
 
Simplify Salesforce Testing with AI-Driven Codeless Tools
Simplify Salesforce Testing with AI-Driven Codeless ToolsSimplify Salesforce Testing with AI-Driven Codeless Tools
Simplify Salesforce Testing with AI-Driven Codeless Tools
 
Role of Automation in Testing
Role of Automation in TestingRole of Automation in Testing
Role of Automation in Testing
 
E-TAIL QA: Approach to E-commerce testing in an Agile environment
E-TAIL QA: Approach to E-commerce testing in an Agile environmentE-TAIL QA: Approach to E-commerce testing in an Agile environment
E-TAIL QA: Approach to E-commerce testing in an Agile environment
 
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...ATAGTR2017 Unified APM: The new age performance monitoring for production sys...
ATAGTR2017 Unified APM: The new age performance monitoring for production sys...
 
Definition Of Done
Definition Of DoneDefinition Of Done
Definition Of Done
 
Definition of done training
Definition of done trainingDefinition of done training
Definition of done training
 
Black Friday Is Approaching. Are You Prepared- Infographic
Black Friday Is Approaching. Are You Prepared- InfographicBlack Friday Is Approaching. Are You Prepared- Infographic
Black Friday Is Approaching. Are You Prepared- Infographic
 
Automating Web Analytics
Automating Web AnalyticsAutomating Web Analytics
Automating Web Analytics
 
Building Test Automations the agile way
Building Test Automations the agile way Building Test Automations the agile way
Building Test Automations the agile way
 
London SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingLondon SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error Handling
 
Definition of Done
Definition of DoneDefinition of Done
Definition of Done
 

Andere mochten auch

Atl elevate programmatic developer slides
Atl elevate programmatic developer slidesAtl elevate programmatic developer slides
Atl elevate programmatic developer slidesDavid Scruggs
 
Hands-On Workshop: Introduction to Development on Force.com for Developers
Hands-On Workshop: Introduction to Development on Force.com for DevelopersHands-On Workshop: Introduction to Development on Force.com for Developers
Hands-On Workshop: Introduction to Development on Force.com for DevelopersSalesforce Developers
 
Apex code-fundamentals
Apex code-fundamentalsApex code-fundamentals
Apex code-fundamentalsAmit Sharma
 
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)Salesforce Developers
 
Apex basics-for Beginners
Apex basics-for BeginnersApex basics-for Beginners
Apex basics-for Beginnershrakhra
 
Salesforce Presentation
Salesforce PresentationSalesforce Presentation
Salesforce PresentationChetna Purohit
 
Salesforce Basic Development
Salesforce Basic DevelopmentSalesforce Basic Development
Salesforce Basic DevelopmentNaveen Dhanaraj
 

Andere mochten auch (12)

Interview questions
Interview   questionsInterview   questions
Interview questions
 
Atl elevate programmatic developer slides
Atl elevate programmatic developer slidesAtl elevate programmatic developer slides
Atl elevate programmatic developer slides
 
Hands-On Workshop: Introduction to Development on Force.com for Developers
Hands-On Workshop: Introduction to Development on Force.com for DevelopersHands-On Workshop: Introduction to Development on Force.com for Developers
Hands-On Workshop: Introduction to Development on Force.com for Developers
 
Workflow in Salesforce
Workflow in SalesforceWorkflow in Salesforce
Workflow in Salesforce
 
Apex code-fundamentals
Apex code-fundamentalsApex code-fundamentals
Apex code-fundamentals
 
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
 
Intro to Apex Programmers
Intro to Apex ProgrammersIntro to Apex Programmers
Intro to Apex Programmers
 
Apex basics-for Beginners
Apex basics-for BeginnersApex basics-for Beginners
Apex basics-for Beginners
 
Introduction to Apex for Developers
Introduction to Apex for DevelopersIntroduction to Apex for Developers
Introduction to Apex for Developers
 
Sfdc Knowledge
Sfdc KnowledgeSfdc Knowledge
Sfdc Knowledge
 
Salesforce Presentation
Salesforce PresentationSalesforce Presentation
Salesforce Presentation
 
Salesforce Basic Development
Salesforce Basic DevelopmentSalesforce Basic Development
Salesforce Basic Development
 

Ähnlich wie Triggers for Admins: A Five-step Framework for Creating Triggers

Global Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul EventGlobal Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul EventLemi Orhan Ergin
 
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...OW2
 
Triggers for Admins: A Five-step Framework for Creating Triggers
Triggers for Admins: A Five-step Framework for Creating TriggersTriggers for Admins: A Five-step Framework for Creating Triggers
Triggers for Admins: A Five-step Framework for Creating TriggersSalesforce Developers
 
iOS Development at Scale @Chegg
iOS Development at Scale @CheggiOS Development at Scale @Chegg
iOS Development at Scale @CheggGalOrlanczyk
 
Denver Salesforce DUG DF 2018 roundup
Denver Salesforce DUG DF 2018 roundup Denver Salesforce DUG DF 2018 roundup
Denver Salesforce DUG DF 2018 roundup Mike Tetlow
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekNacho Cougil
 
Ls14 798 bolen_b
Ls14 798 bolen_bLs14 798 bolen_b
Ls14 798 bolen_bDon Bolen
 
TrailblazerDX Motihari.pptx
TrailblazerDX Motihari.pptxTrailblazerDX Motihari.pptx
TrailblazerDX Motihari.pptxOm Prakash
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)ssusercaf6c1
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)Nacho Cougil
 
How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...Max Barrass
 
Continuous Deployment and Testing Workshop from Better Software West
Continuous Deployment and Testing Workshop from Better Software WestContinuous Deployment and Testing Workshop from Better Software West
Continuous Deployment and Testing Workshop from Better Software WestCory Foy
 
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowMay 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowAdam Doyle
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with SeleniumDave Haeffner
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Applitools
 

Ähnlich wie Triggers for Admins: A Five-step Framework for Creating Triggers (20)

Global Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul EventGlobal Day of Coderetreat'14 - Istanbul Event
Global Day of Coderetreat'14 - Istanbul Event
 
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
 
Triggers for Admins: A Five-step Framework for Creating Triggers
Triggers for Admins: A Five-step Framework for Creating TriggersTriggers for Admins: A Five-step Framework for Creating Triggers
Triggers for Admins: A Five-step Framework for Creating Triggers
 
Usable Software Design
Usable Software DesignUsable Software Design
Usable Software Design
 
iOS Development at Scale @Chegg
iOS Development at Scale @CheggiOS Development at Scale @Chegg
iOS Development at Scale @Chegg
 
Denver Salesforce DUG DF 2018 roundup
Denver Salesforce DUG DF 2018 roundup Denver Salesforce DUG DF 2018 roundup
Denver Salesforce DUG DF 2018 roundup
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech Week
 
Agile Methodology - Agile Project Management Training
Agile Methodology - Agile Project Management TrainingAgile Methodology - Agile Project Management Training
Agile Methodology - Agile Project Management Training
 
Ls14 798 bolen_b
Ls14 798 bolen_bLs14 798 bolen_b
Ls14 798 bolen_b
 
TrailblazerDX Motihari.pptx
TrailblazerDX Motihari.pptxTrailblazerDX Motihari.pptx
TrailblazerDX Motihari.pptx
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
 
How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...
 
Continuous Deployment and Testing Workshop from Better Software West
Continuous Deployment and Testing Workshop from Better Software WestContinuous Deployment and Testing Workshop from Better Software West
Continuous Deployment and Testing Workshop from Better Software West
 
UPC Plone Testing Talk
UPC Plone Testing TalkUPC Plone Testing Talk
UPC Plone Testing Talk
 
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowMay 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
Continuous feature-development
Continuous feature-developmentContinuous feature-development
Continuous feature-development
 
Automated testing
Automated testingAutomated testing
Automated testing
 

Mehr von Salesforce Developers

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSalesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceSalesforce Developers
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base ComponentsSalesforce Developers
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsSalesforce Developers
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaSalesforce Developers
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentSalesforce Developers
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsSalesforce Developers
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsSalesforce Developers
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsSalesforce Developers
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and TestingSalesforce Developers
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilitySalesforce Developers
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce dataSalesforce Developers
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionSalesforce Developers
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPSalesforce Developers
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceSalesforce Developers
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureSalesforce Developers
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DXSalesforce Developers
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectSalesforce Developers
 

Mehr von Salesforce Developers (20)

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component Performance
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base Components
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer Highlights
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX India
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local Development
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web Components
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web Components
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer Highlights
 
Live coding with LWC
Live coding with LWCLive coding with LWC
Live coding with LWC
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and Testing
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura Interoperability
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce data
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCP
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in Salesforce
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data Capture
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DX
 
Get Into Lightning Flow Development
Get Into Lightning Flow DevelopmentGet Into Lightning Flow Development
Get Into Lightning Flow Development
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS Connect
 

Kürzlich hochgeladen

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 

Kürzlich hochgeladen (20)

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 

Triggers for Admins: A Five-step Framework for Creating Triggers

  • 1. Triggers for Admins: A Five-step Framework for Creating Triggers (a play in 5 acts) Veronica Beck Ashima Saigal @gandhilover
  • 2. Ashima Saigal Database Sherpa founder Summer 2014 MVP
  • 3. Veronica Beck Bigger Boat Consulting Senior Consultant
  • 4. Setting “We want our own custom campaign member statuses, but it’s a pain to have to add them every time we create a campaign.” – Celeste, yoga studio owner
  • 5. Audience Participation We have some suggestions: ● Breathe! You can do it. ● Replace trepidation with curiosity. ● Know this won’t happen overnight. ● Remember, you are not alone.
  • 6. Triggers for Admins Act 1: Where do I write code? Act 2: Gather Your Resources Act 3: Clarify Your Requirements Act 4: Code and Test Act 5: Finalize and Launch!
  • 7. Act 1: Where do I write code? Developer Org: https://developer.salesforce.com/gettingstarted
  • 8. Act 1: Where do I write code?
  • 9. Act 1: Where do I write code? Go to Setup. Find the object where you want the trigger. Click on Triggers.
  • 10. Act 1: Where do I write code? Click the New button, and voila!
  • 11. Act 1: Where do I write code? Some other tools for writing code: • Salesforce Developer Console • Eclipse [there are many more!]
  • 12. Act 2: Gather your resources ● www.sfdc99.com ● Creator David Liu presents: “Anyone can learn to code Apex!” On Wednesday at 11 am
  • 13. Act 2: Gather your resources ● Power of Us HUB (nonprofits) http://www.salesforcefoundation.org/help/power-of-us-hub/ ● Success Community: (Salesforce online community) ● Local User Groups (in person meetings) ● Developer User Groups (in person meetings) ● Network at Dreamforce!
  • 14. Act 3: Clarify Requirements ● What problem are you trying to solve? o Inconsistent campaign member statuses ● What needs to happen? o Auto creation of desired member statuses ● When does it need to happen? o When a new campaign is created ● Should it always happen for all records? o Only for workshop type campaigns
  • 15. Act 3: Clarify Requirements Write it “In English” (aka pseudo code): When a campaign is inserted ● Check if it’s a workshop campaign ● If it is a workshop campaign … o Get rid of the default Campaign Statuses o Add the following campaign statuses:  Invited (default)  Accepted (responded)  Attended (responded)  No Show
  • 16. Act 4: Code and Test ● Recap o Set up your coding environment o Go through some tutorials o Clarify what you’re trying to do ● Get ready, set, go! ● Search for code, copy and paste.
  • 17. Act 4: Code and Test
  • 18. Act 4: Code and Test
  • 19. Act 4: Code and Test Design Pattern 1: Use Trigger.New Trigger.new contains all records that are being inserted or updated Loop through the trigger.new collection Do something with each record Code Sample: For (Campaign c : trigger.new){ // This is the beginning of the loop //do something with each record } //this is the end of the loop
  • 20. Act 4: Code and Test
  • 21. Act 4: Code and Test
  • 22. Act 4: Code and Test
  • 23. Act 4: Code and Test
  • 24. Act 4: Code and Test
  • 25. Act 4: Code and Test
  • 26. Act 4: Code and Test
  • 27. Act 4: Code and Test Design Pattern 2: Use Lists and Sets Lists and Sets are like a bucket to hold records for later processing
  • 28. Act 4: Code and Test
  • 29. Act 4: Code and Test
  • 30. Act 4: Code and Test
  • 31. Act 4: Code and Test
  • 32. Act 4: Code and Test
  • 33. Act 4: Code and Test Design Pattern 3: Inserts, Updates, Deletes Outside of Loops For (Campaign c : workshopCampaigns) { //start of the loop CampaignMemberStatus myCMS = ….. myStuff.add(myCMS); } // end of the loop Insert myStuff ; Insert is happening AFTER the loop
  • 34. Act 4: Code and Test ● Common design elements o Loop through trigger.new (or trigger.old) o Use collections to hold records to process o Do inserts, updates, and deletes outside of your loops ● Other helpful Tips o Comment your code! o Use system.debug for troubleshooting
  • 35. Act 5: Finalize and Launch • Ask users to test with real-life scenarios • Revise code, have users re-test • Write test methods – Sfdc99.com has examples and tutorial – Force.com Apex Developer Guide http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm • Deploy! – Use Salesforce change sets and deployment connections in Setup area
  • 37. Begin Your Coding Journey Today! ● Set up your FREE developer account ● Find a mentor – introduce yourself to at least three people and tell them you’re looking for help with coding. ● Visit sfdc99.com. ● Celebrate the beginning of your journey!
  • 38. Resources Beginner Tutorial - http://www.sfdc99.com/beginner-tutorials/ Salesforce Developer Forum - https://developer.salesforce.com/forums/ Trigger Best Practices - http://www.iterativelogic.com/salesforce-apex-trigger-best-practices/ Trigger Order of Execution - http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execu tion.htm Writing Bulk Triggers - http://blog.jeffdouglas.com/2009/04/20/writing-bulk-triggers-for-salesforce/ Force.com Apex Developer Guide - http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm

Hinweis der Redaktion

  1. VERONICA: The setting for our play is a yoga studio that offers workshops. They track their workshops with Salesforce campaigns, and they track the people they invite by using campaign members. They’re finding that the standard Campaign member Statuses of Invited and Sent aren’t what they need. They want their own custom campaign member statuses, but it’s a pain to have to add them every time. Veronica has been asked by the studio manager to find a solution to this problem.
  2. VERONICA: To get the most out of this production, we have some suggestions for you: First is: Breathe! You can do it. Everyone has to start somewhere, and Next: See if you can start to replace any feelings of trepidation with a sense of curiosity and exploration. If you tend to think "What if I get it wrong???" Don't worry, you will! But that's ok. You won't break Salesforce. And you'll learn a lot along the way. If you can focus on the learning, and the adventure of it, it will be a lot more enjoyable. Also: Know this won't happen overnight .... it takes time, and practice. And that's ok. Little by little you’ll get there. Finally: Remember, you're not alone! There are wonderful people in the Salesforce community who are generous with their time and help. and plenty of resources to help you out along the way.
  3. VERONICA: Our play is in 5 acts: Act 1: Set up your environment, or Where do I write code? [TRANSITION] Act 2: Gather Your Resources (Get help!) Act 3: Clarify Your Requirements: What am I doing again? Act 4: Code and Test! Act 5:Finalize and launch! Let’s, start by taking 3 deep breaths to get transported to the yoga studio:
  4. ASHIMA: The scene: Ashima and Veronica met at DreamForce last year. Veronica knows that she is going to need some help, so she set up a meeting to talk about her needs. They are meeting via Google Hangout. VERONICA: Ashima, I have a Salesforce thing I’m trying to do. I want to have some different campaign member statuses added every time we create a new campaign. I thought maybe I could do it with a workflow rule, but it looks like that won’t work. So I think I’m going to need to write a trigger. I have no idea how to get started. I don’t even know where in Salesforce I would write code, let alone what to write. Can you help me? ASHIMA: Absolutely Veronica, first, let’s discuss some environments you might want to set up for yourself to get started. There are two options. First, you can create a Developer Org. (FREE! You can have as many as you want!) Enterprise Edition, 2 users. Terms of use are you're not supposed to run your business off of this -- it's a place where you can practice and learn. This is great if you’re in the “I want to expand my skills” camp, and don’t have an immediate need to add code to your organization. A great place to build and learn, no one else will be in it, you can do want you want, and experiment.) Even if you do have an immediate business need, this is still a great place to learn, without fear of destroying anything. :-) Considered a Production org when logging in. (login.salesforce.com, not test.salesforce.com)
  5. ASHIMA: Second, you can create a sandbox which is a copy of your production database, minus the data, unless you purchase a sandbox with data. All the custom configuration is there -- custom objects, workflow and validation rules, custom fields, picklist values, custom profiles, etc. The advantage is that you’re working in the environment you eventually want to deploy to, so if you need to work with any custom fields or objects, or want to see how workflow rules interact with the code you’re writing, it’s already set up. You must deploy from a sandbox, so you can get started in a development organization, but then, you must move your code to a sandbox and deploy to production from there. Some of the nonprofit developers knows that you can get a few free sandboxes with your edition. If you are not a nonprofit, that is not available free. Disadvantages: Cost. [info about cost here] Less storage space. VERONICA: What does deploy mean? ASHIMA : It means moving your code from the testing environment to a live, production environment, but we have a few more steps before you can do that, we’ll get to deployment. VERONICA: {Deep breath}, okay.
  6. ASHIMA: So, now, once you have your environment set up, you will want to begin to play around. I suggest you do this in your sandbox, since you’re a nonprofit and have a few free sandboxes to play with. Now to begin writing your code, start by navigating to the Trigger area of the object you want to write your Trigger on. VERONICA:The campaign member? ASHIMA: Well, that might seem like where you’d want to write the trigger, but think about it for a second -- what do you want to happen? VERONICA: I want to add new campaign member statuses. ASHIMA: And when do you want to create them? VERONICA: When we add a new campaign. ASHIMA: Ok, so where would you want to create the trigger? VERONICA: [pause] Oh … the campaign, right? Because it’s like a workflow rule - I want the trigger code to run when a Campaign is created. ASHIMA: Right! VERONICA: Ok, that makes sense.
  7. ASHIMA: Alright, now to write your code, you click on the Trigger and click the New button. The code area opened up and I can begin writing. VERONICA: Ok, at least I know where to start. ASHIMA: Yes. And just so you know, doing your coding right here in Salesforce is a quick and easy way to get started, but once you get more familiar with how everything works, you might also want to check out some of the other tools people use to write code. For example, the Salesforce Developer Console, Eclipse, or Workbench. Those tools offer some great functionality, but there’s also a learning curve with them. So for now, let’s stick to doing our coding here within Salesforce. VERONICA: Okay, but I’m nervous about this - it seems like there’s a lot to learn! ASHIMA: It’s okay to be nervous Veronica. But, I’ll help and there are a lot of resources available. Let’s look at some together. VERONICA: Ok, sounds good!
  8. ASHIMA: The most excellent tool available is this sfdc99, which is coding lessons for the 99% (meaning for everyone who is not a programmer). This great site was written by a self-taught Google engineer, who started out as a Salesforce Admin. {Look at audience: He is also hosting a session : Wednesday 11AM – Anyone can learn to code Apex!} This blog contains a beginners tutorial that will take you step by step through the process of writing code, all the syntax you need, … plus he’s funny. Also just added a Newbies Forum, where you can ask any coding question you have. An amazing resource. VERONICA: Wow, I need to spend some time on that web site! ASHIMA: Yes, but that’s not all. There is also a great resource that is just for nonprofits called the Power of Us Hub. Join that and look for the nonprofit developer chatter group. VERONICA: I’m in there, but didn’t realize there was a developer group for nonprofits, great! ASHIMA: Yup, and I also recommend the Success community, user groups, developer user groups and to network here, at DreamForce. There are lots of folks willing to help. Along with me. VERONICA: I’m really glad to know about all these resources. ASHIMA : Now, Veronica, go ask the yoga studio manager what the specific needs are for the campaigns. The more you can get clear in your own mind about what it is you’re trying to do, the better prepared you’ll be not only to write the code, but also ask relevant questions and get help. VERONICA: I’ll do that! Thanks for your help. Namaste ASHIMA: Namaste
  9. ASHIMA: Setting: the yoga studio. I’m Celeste, the studio manager. ASHIMA: Namaste, Veronica how are you today? VERONICA: Namaste Celeste, I’m well. I wanted to ask you about the issue you mentioned with tracking our workshops in Salesforce. Can you explain to me again what’s going on? [click: What problem are you trying to solve?] ASHIMA: Yes, of course. So, you know we’re trying to track who’s coming to our trainings. I want to be able to see who’s signing up, but not showing up. It seems to be a problem lately. I think we need to start charging people ahead of time. But I’m having a hard time tracking it. Zola and Etta are entering the data, but they keep forgetting to add the right statuses, so we can’t mark someone as a No Show. [transition: inconsistent campaign member statuses] VERONICA: I made a template campaign for them that I showed them how to clone … isn’t that working? ASHIMA: They said they can never find it, or they forget to use it. It’s kind of driving me crazy. VERONICA: Hmm, ok. So, you want a way for those statuses to be there without anyone having to manually go in and create them? ASHIMA: Yes, that would be great! VERONICA: And we’re talking about the campaign member statuses, right? ASHIMA: I don’t know what you call it, I just need a way to track who shows up and who doesn’t. VERONICA: Ok. ASHIMA: Oh, and I want to know who we’re inviting in the first place, and who lets us know they’re coming. And who actually came. Along with who said they were coming but didn’t. VERONICA: Ok. So, it sounds like it would work to maybe have these statuses you could see: Invited, Accepted, Attended, and No Show? ASHIMA: Yes! VERONICA: Great, I think I have it. ASHIMA: So, do you think you can have it done this week? You can just set Salesforce up to do that, right? How hard can it be??? VERONICA: Well …it’s going to involve actual coding, so I’m going to have to take some time to learn how to do it. But the good news is, it’s a great thing for me to learn, and it will really help us out in the long run. ASHIMA: [Sigh]. Ok, do what you have to do. VERONICA: Ok. Oh wait, one more question … this is only for trainings and workshops, right? Not for our mailings, right? ASHIMA: Just the workshops. VERONICA: Ok, got it.
  10. ASHIMA: Veronica and Ashima meet on Google Hangout VERONICA: Ok Ashima, I talked to my studio manager and I think I know what needs to happen now. What’s next? How do I figure out how to write the trigger? ASHIMA: Before I write the actual code, I usually write “pseudo code” , which is writing out at a high level, in English, what the code needs to do. It helps me clarify my thoughts on how to structure the code. VERONICA: Can you show me what you mean? ASHIMA: Sure. Here’s what some pseudo code might look like for your trigger. [transition: show pseudo code]
  11. VERONICA: Ok, so now I know: Where to write the code -- in my sandbox, or in a developer org. I’ve gone through some of the great sfdc99 tutorials, and I know other resources I can use to help me I have an idea of what I want my code to do … I’ve written it out in English, and I’ve thought about what should happen when. I guess it’s time to start coding! I’m going to start by doing a search to see if there’s some sample code out there that someone already wrote. Maybe I can copy and paste it. ASHIMA: That sounds like a great start Veronica. Get in touch with me when you have more questions and we can reconnection. VERONICA: Sounds good. Namaste Ashima. ASHIMA: Namaste Veronica.
  12. VERONICA: Setting: A few days later, another video chat with Ashima. Ok Ashima, I did a Google search and found a post from someone who needed to do pretty much what I’m trying to do! I don’t totally understand the code … but I went ahead and copied and pasted it, and saved it into my trigger. Can you explain what some of these things mean? For example, what is trigger.new? ASHIMA: Sure! Trigger.new is a collection that holds all of the new Campaign records that were just inserted. VERONICA: All of the campaign records? I don’t get it … aren’t I just creating one new Campaign record when I create a Campaign? ASHIMA: Yes, but what if you upload a bunch of new Campaigns with the Data Loader? VERONICA: Ohhh, I hadn’t thought of that. ASHIMA: Pretty much every trigger will follow some version of this pattern: using the trigger.new (or trigger.old) collection, looping through the collection, and doing something with the records in the collection. In this code, you’re looping through the collection of campaigns that were created, and adding new campaign member statuses to each one. VERONICA: You said there’s a trigger.old collection too? ASHIMA: Yes, that one is used in updates or deletes. It holds the old versions of the records that were updated or deleted. Trigger.new holds the new versions. VERONICA: Ok, I know I’m not going to understand all of this all at once … but I really want to test it and see if it works. How can I do that? ASHIMA: Now that you’ve saved the trigger, you can go ahead and just create a new Campaign in Salesforce, and then check the Campaign Member Statuses! VERONICA: Cool! I’m going to try that right now.
  13. VERONICA: Setting: A few days later, another video chat with Ashima. Ok Ashima, I did a Google search and found a post from someone who needed to do pretty much what I’m trying to do! I don’t totally understand the code … but I went ahead and copied and pasted it, and saved it into my trigger. Can you explain what some of these things mean? For example, what is trigger.new? ASHIMA: Sure! Trigger.new is a collection that holds all of the new Campaign records that were just inserted. VERONICA: All of the campaign records? I don’t get it … aren’t I just creating one new Campaign record when I create a Campaign? ASHIMA: Yes, but what if you upload a bunch of new Campaigns with the Data Loader? VERONICA: Ohhh, I hadn’t thought of that. ASHIMA: Pretty much every trigger will follow some version of this pattern: using the trigger.new (or trigger.old) collection, looping through the collection, and doing something with the records in the collection. In this code, you’re looping through the collection of campaigns that were created, and adding new campaign member statuses to each one. VERONICA: You said there’s a trigger.old collection too? ASHIMA: Yes, that one is used in updates or deletes. It holds the old versions of the records that were updated or deleted. Trigger.new holds the new versions. VERONICA: Ok, I know I’m not going to understand all of this all at once … but I really want to test it and see if it works. How can I do that? ASHIMA: Now that you’ve saved the trigger, you can go ahead and just create a new Campaign in Salesforce, and then check the Campaign Member Statuses! VERONICA: Cool! I’m going to try that right now.
  14. VERONICA: Hey, it worked! Kind of. It looks like it added some new statuses. But I noticed a couple of things -- they’re not exactly the statuses I wanted. And those default statuses of Sent and Responded are still there. ASHIMA: Let’s tackle those issues one at a time. Let’s go back to the code, and tell me if you can find where you might change what those new statuses say. VERONICA: Ok.
  15. VERONICA: Hey, I see it right here -- these are the statuses that were added! Can I just change them to be what I want? ASHIMA: Give it a try and see! VERONICA: This is kind of fun! Oh, but they only added three statuses, and I want four. I’m guessing I can just copy and paste the code? ASHIMA: Now you’re getting the hang of it! VERONICA: Oh, and there’s an explanation right within the code of looping through the trigger.new collection here, and which statuses they’re going to add -- that’s helpful! ASHIMA: Yes, those are comments! You definitely want to get in the habit of using comments within the code to explain what’s going on. It will help anyone else who happens to look at your code … and it will help YOU, when you go back to look at code you wrote a while ago and can’t remember why you wrote it! Take the time to do it -- believe me, you’ll thank yourself later! Just use two forward slashes before any comments you want to make - that will tell the compiler it’s a comment, not code. Oh, and emember the pseudo code we wrote? I’ll often put that into my brand new trigger as comments, to give me a starting place to structure my code, and to remind me of how I want the code to work. Actually, let’s go take a look at that pseudo code now.
  16. ASHIMA: When you look at the pseudo code, and the actual code, what do you notice? VERONICA: Well … I see in our pseudo code we have “Add the following campaign statuses”, and I see where in the code that’s happening. But what about get rid of the default campaign statuses? Oh … right … that’s what we saw when we tried the code out -- that part isn’t there! ASHIMA: Right! There’s no code to delete those yet, so they showed up when you created the Campaign. Notice anything else that’s missing? VERONICA: Hmm …. we say to check if it’s a workshop campaign … but I don’t think that’s happening anywhere either, is it? ASHIMA: Good catch! See, the pseudo code can remind you of the requirements. VERONICA: Ok, it’s kind of making sense. So can we add those missing pieces? ASHIMA: Yes, I happen to have a version of the code that I think will do the trick. Let’s take a look at it.
  17. ASHIMA: Notice that the very first line of pseudo code was “After a campaign is inserted.” Here’s what that translates to in the trigger -- after insert. You define when you want your code to run. You could set your trigger to fire on more than one event -- after insert, after update, before delete, etc. There are some things you can do before insert that you can’t do after, and vise versa. Next is checking to see if it’s a workshop campaign. Here’s where we’re doing that. VERONICA: Ok, I can see that. But what are all those lists and sets for towards the top of the code? ASHIMA: That’s another common element you’ll see in triggers. Lists and sets are collections. They’re used to hold records that you’re going to process. In this trigger we’re going to have a list of campaign member statuses to delete, another list of campaign member statuses to add, and a set of campaign IDs of any workshop type Campaigns that were inserted. Don’t worry too much about these details now -- they’ll become more familiar to you as you practice. And remember, the website sfdc99.com will explain all of this in detail and give you lots of ways to practice. For now, just know that you’ll likely use lists and sets in your triggers. VERONICA: Ok. What is that part there that says “system.debug we added this campaign for processing”? What does that do? ASHIMA: System.debug is a really helpful tool. Anything you write as a system.debug statement will get written out in the debug logs. It’s a way for you to troubleshoot what’s happening in the code as it processes. In this example, for every workshop type campaign that was created, there would be a line in the debug log that said “We added this campaign for processing”, along with the campaign name. VERONICA: Where are the debug logs? ASHIMA: If you go to the Setup area and type Debug in the search, you’ll find them -- in the Monitor section. You need to set up a debug log for yourself by clicking New in the debug log area and adding your name. Then after you create a Campaign, you can look at the debug log and find your debug statement. Here, let’s take a quick look.
  18. ASHIMA: This is a snippet from the debug log. Looks like you have a workshop coming up called How to be a Zen Goddess -- I want to sign up! VERONICA: Me too! :-)
  19. ASHIMA: Ok, let’s finish looking at the rest of the code. I’ve added a section to delete the default campaign member statuses. And finally, the bottom part is where the statuses you want are created. VERONICA: Ok, there are a lot of details I still don’t get, but I get the general idea of what’s happening. This is great! I do have just one more question for now … back to those lists and sets. The “cmsToInsert” list -- it looks like you’re adding the new campaign member statuses while you’re looping through the workshop campaigns …. but then it looks like you insert them again at the bottom of the code. ASHIMA: Ah, great question. So, inside this loop is where we’re just putting things into our collection -- our “cmsToInsert” list. We’re not actually inserting them into Salesforce yet. The collection is just a storage place to hold all the records we’re going to process. Then, after we’re done going through the loop, that Insert statement at the bottom is where we’re actually creating the records in Salesforce. This is another important design pattern -- you generally want to do your inserts, updates, and deletes outside of any loops, otherwise you can run into some errors around what are called Governor Limits. Again, don’t worry too much about it now. You’ll get the hang of it with more practice. VERONICA: Ok, there’s a lot to learn! But at least I feel good about getting started.
  20. ASHIMA: Yes, there is a lot to learn, but you’re off to a great start! Here are some of the key things we talked about: In the majority of triggers you’ll be looping through trigger.new or trigger.old. Use collections to hold records you’re going to process Do your inserts, updates, and deletes outside of loops Be sure to comment your code You can use system.debug and the debug log to see what’s happening when the code runs. VERONICA: Thanks Ashima, this has been super helpful. So … now that the code’s working … can I just copy and paste it to my production org?
  21. { POSSIBLY NEED TO REWRITE DEPENDING ON THE ENDING OF ACT 4} This is the final act of our play. VERONICA: Great, it’s ready to go to production. What was that called again to move my code from sandbox into production? ASHIMA: Deploy, but there are still a few more steps I’d like to recommend before deployment.. First, it’s important to get your users to test it out. I’d recommend asking Etta and Zola to log into the Sandbox and make them go through the steps of creating some real campaigns. You never know what you might have missed in your code that the users might uncover. VERONICA: Oh, that makes sense. Okay, then are we ready to go to production? ASHIMA: Well, not yet. After they test and if they find anything, you’ll need to revise your code. And, then, ask them to retest the code again. Once they agree it’s working good, there is one final step before deployment and that’s called test coverage. You do that with something called test cases. VERONICA: Wow, there sure is a lot of testing. Seems overboard to me. ASHIMA: Actually, it’s super important to test your code as this is running realtime in the database. So, you noticed when you created a campaign, your code ran immediately. When you create test cases, it helps stop the system from getting broken. For example, if you introduced a new package or new code to your instance, it might interfere with this code. The test cases can check to make sure you don’t break your instance of Salesforce. VERONICA: I hadn’t thought about that. Well, I guess testing is pretty important. ASHIMA: Yes. I highly recommend reading up on testing just like you have done here with your coding. Take a look at the SFDC99 resource again, there is a section on testing. Also, the Developer API also offers some great suggestions as do a few other web site you can find. VERONICA: Okay, so after I do all this, how do I deploy. ASHIMA: We’ll do that, but the SFDC99 documentation has help for that, but don’t be surprised if you run into errors or trouble. But, first, we need to test with users, revise and test again and then write test classes. The deployment is really the last and final step. I’ll help you with that as well and may see what you can do on your own. VERONICA: Great, after doing this much on my own, I’m starting to feel a bit more confident. ASHIMA: That’s great Veronica, you have done an amazing job and with very little help from me. You’re on the right path and you’ve been asking some great questions. Keep it up and once you get the deployed, I need some help from you with a report I’m trying to create. VERONICA: Help from me? Don’t you know it all? ASHIMA: Not really, I know some things, but I don’t know enough about Analytics and you’re the guru I hear. So, when you have some time, can you help me? VERONICA: Of course. ASHIMA: Great. Namaste Veronica! VERONICA: Namaste Ashima!
  22. Bow to the audience (and pretend to catch flowers being thrown at us and smelling them) SMILE BROADLY.
  23. { POSSIBLY NEED TO REWRITE DEPENDING ON THE ENDING OF ACT 4} This is the final act of our play. VERONICA: Great, it’s ready to go to production. What was that called again to move my code from sandbox into production? ASHIMA: Deploy, but there are still a few more steps I’d like to recommend before deployment.. First, it’s important to get your users to test it out. I’d recommend asking Etta and Zola to log into the Sandbox and make them go through the steps of creating some real campaigns. You never know what you might have missed in your code that the users might uncover. VERONICA: Oh, that makes sense. Okay, then are we ready to go to production? ASHIMA: Well, not yet. After they test and if they find anything, you’ll need to revise your code. And, then, ask them to retest the code again. Once they agree it’s working good, there is one final step before deployment and that’s called test coverage. You do that with something called test cases. VERONICA: Wow, there sure is a lot of testing. Seems overboard to me. ASHIMA: Actually, it’s super important to test your code as this is running realtime in the database. So, you noticed when you created a campaign, your code ran immediately. When you create test cases, it helps stop the system from getting broken. For example, if you introduced a new package or new code to your instance, it might interfere with this code. The test cases can check to make sure you don’t break your instance of Salesforce. VERONICA: I hadn’t thought about that. Well, I guess testing is pretty important. ASHIMA: Yes. I highly recommend reading up on testing just like you have done here with your coding. Take a look at the SFDC99 resource again, there is a section on testing. Also, the Developer API also offers some great suggestions as do a few other web site you can find. VERONICA: Okay, so after I do all this, how do I deploy. ASHIMA: We’ll do that, but the SFDC99 documentation has help for that, but don’t be surprised if you run into errors or trouble. But, first, we need to test with users, revise and test again and then write test classes. The deployment is really the last and final step. I’ll help you with that as well and may see what you can do on your own. VERONICA: Great, after doing this much on my own, I’m starting to feel a bit more confident. ASHIMA: That’s great Veronica, you have done an amazing job and with very little help from me. You’re on the right path and you’ve been asking some great questions. Keep it up and once you get the deployed, I need some help from you with a report I’m trying to create. VERONICA: Help from me? Don’t you know it all? ASHIMA: Not really, I know some things, but I don’t know enough about Analytics and you’re the guru I hear. So, when you have some time, can you help me? VERONICA: Of course. ASHIMA: Great. Namaste Veronica! VERONICA: Namaste Ashima!