triggers for admins: a five-step framework for creating triggers

29
A 5-Step Framework to Tackling Your First Trigger With Confidence (a play in 5 acts) Veronica Beck @Twitter Handle Ashima Saigal @gandhilover

Upload: salesforce-developers

Post on 01-Jul-2015

214 views

Category:

Technology


0 download

DESCRIPTION

Have you felt intimidated by the thought of writing code? Are you an experienced Salesforce Administrator and would like to take the leap into writing your own Apex triggers? Join us to gain the tools and confidence to write your first trigger. Using specific examples and real-life scenarios, we'll walk through a concrete framework to approach the process of planning, designing, and coding a trigger.

TRANSCRIPT

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

A 5-Step Framework to Tackling Your First Trigger With Confidence(a play in 5 acts)Veronica Beck

@Twitter Handle

Ashima Saigal

@gandhilover

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

Safe Harbor

Safe harbor statement under the Private Securities Litigation Reform Act of 1995:

This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.

 

The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site.

 

Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.

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

Overview

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

Cast

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

Ashima Saigalis the founder of Database Sherpa. She is a certified Salesforce Administrator, Force.com Developer & Summer 2014 MVP.

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

Veronica Beckis a certified Force.com Developer, and a consultant with Bigger Boat Consulting in Seattle.

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

Setting

Running time is exactly 40 minutes with no intermission

The setting: a nonprofit yoga studio that offers teacher trainings andworkshops. They track their trainings as campaigns, with the peoplethey invite and who attend as campaign members. Campaignmember statuses they use are "Invited; Accepted; Attended; NoShow. As an aside, they also use campaigns to track theirfundraising events and mailings.

Director: Ashima SaigalWriter/Producer: Veronica BeckGrip: Salesforce.com

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

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.

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

Triggers with Confidence

Act 1: Set up Your Environment

Act 2: Gather Your Resources

Act 3: Clarify Your Requirements

Act 4: Code and Test

Act 5: Finalize and Launch!

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

Act 1: Set up Your Environment (Where do I write code??)

Developer Org: https://developer.salesforce.com/gettingstarted

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

Act 1: Where do I write code?? (continued)

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

Once you have an org, either a free Developer org or asandbox, navigate to the Trigger area of the object youwant to write the trigger on.

Act 1: Where do I write code?? (continued)

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

Act 1: Where do I write code?? (continued)

Click the New button, and voila!

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

Act 2: Help! (Gather your resources)

Salesforce coding lessons for the 99%: http://www.sfdc99.com/

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!

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

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

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

Act 3: Clarify Requirements (continued)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 Statuseso Add the following campaign statuses:

Invited (default) Accepted (responded) Attended (responded) No Show

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

Act 4: Dive in! Code and Test

● Recap

o Know where to code, set up your environment

o Go through some tutorials, gather resources

o Clarify what you’re trying to do

● Search for code, copy and paste!

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

Act 4: Dive in! Code and Test (continued)

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

Act 4: Dive in! Code and Test (continued)

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

Act 4: Dive in! Code and Test (continued)

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

When a campaign is inserted

● If it is a workshop campaign

● Get rid of the default

Campaign Statuses

● Add the following

campaign statuses:

o Invited (default)

o Accepted

(responded)

o Attended

(responded)

o No Show

Act 4: Dive in! Code and Test (continued)

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

Act 4: Dive in! Code and Test (continued)

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

Act 4: Dive in! Code and Test (continued)

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

Act 4: Dive in! Code and Test (continued)

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

Act 4: Dive in! Code and Test (Summary)● 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 Tipso Comment your code!

o Use system.debug for troubleshooting

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

Act 5: Finalize and Launch

● More testing - ask users to test

● Revise again

● Are you ready to go live?

o Test coverage and test classes

o Deploy errors, keep trying. Get help.

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

That’s a Wrap

Applause with standing ovation

Encore Encore Encore

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

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_execution.h

tm

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

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