<commit_before><!doctype html>
<html lang="en">

	<head>
		<meta charset="utf-8">

		<title>Apex Trigger Development - Best Practices</title>

		<meta name="description" content="Apex Trigger Best Practices">
		<meta name="author" content="<NAME>">

		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">

		<link rel="stylesheet" href="css/reveal.css">
		<link rel="stylesheet" href="css/theme/sky.css" id="theme">

		<!-- Code syntax highlighting -->
		<link rel="stylesheet" href="lib/css/zenburn.css">

		<!-- Printing and PDF exports -->
		<script>
			var link = document.createElement( 'link' );
			link.rel = 'stylesheet';
			link.type = 'text/css';
			link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
			document.getElementsByTagName( 'head' )[0].appendChild( link );
		</script>

		<!--[if lt IE 9]>
		<script src="lib/js/html5shiv.js"></script>
		<![endif]-->
	</head>

	<body>

		<div class="reveal">

			<div class="slides">
				<section>
					<h1>Apex Trigger Development</h1>
					<h3>Best Practices</h3>
					<p><small>Presented by <NAME> / <a href="https://twitter.com/scottbcovert">@scottbcovert</a></small></p>
				</section>

				<section>
					<h2>Intro</h2>
					<p>Umm, my workflow rule can't do that-what should I do?</p>
					<img src="http://memecrunch.com/meme/5942Y/apex-trigger/image.gif?w=500&c=1"/>
				</section>

				<section>
					<section>
						<h2>Common Issues</h2>
						<p>The world of Apex development ain't all sunshine and rainbows.</p>
						<img src="http://cdn.meme.am/instances/500x/36001409.jpg"/>
					</section>
					<section>
						<h2>Context</h2>
						<p>Should my logic live in a before or after trigger?</p>
						<p>Null reference? I thought all records have ids?</p>
					</section>
					<section>
						<h2>Bulk DML Operations</h2>
						<p>Umm, you mean you want to insert more than a single account at once?</p>
					</section>
					<section>
						<h2>SOQL inside For Loops</h2>
						<p>...what's a governor limit?</p>
					</section>
					<section>
						<h2>Logic inside Triggers</h2>
						<p>Unit tests?</p>
					</section>
					<section>
						<h2>Multiple Triggers per Object</h2>
						<img src="http://cdn.meme.am/instances/500x/59330053.jpg"/>
					</section>
					<section>
						<h2>Recursion</h2>
						<img height="550px" src="http://caseelse.net/wp-content/uploads/2008/05/recursionagain.jpg"/>
					</section>
					<section>
						<h2>Spaghetti Code</h2>
						<p>...but it's sorta working</p>
					</section>
				</section>

				<section>
					<section>
						<h2>Best Practices</h2>
						<img height="550px" src="http://www.sqlsoldier.com/wp/wp-content/uploads/2012/02/BestPractices.jpg"/>
					</section>
					<section>
						<h2>Context</h2>
						<p>Before:</p>
						<ul>
							<li>Set/change field values before writing to database</li>
							<li>No Id value yet for Insert triggers</li>
						</ul>
						<p>After:</p>
						<ul>
							<li>Id values can be safely mapped</li>
						</ul>
						<p>Insert:</p>
						<ul>
							<li>No Trigger.old or Trigger.oldMap</li>
						</ul>
						<p>Update:</p>
						<ul>
							<li>Can update original object (be careful of recursion)</li>
						</ul>
					</section>
					<section>
						<h2>Context Cheat Sheets</h2>
						<p><a href="https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm">Trigger Context Variables</a></p>
						<p><a href="https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables_considerations.htm">Context Variable Considerations</a></p>
					</section>
					<section>
						<h2>Bulkification</h2>
						<img src="https://pbs.twimg.com/media/BLhjL36CUAA3HWc.jpg"/>
					</section>
					<section>
						<h2>Don't Do This!</h2>
						<pre><code data-trim contenteditable>
trigger accountTestTrggr on Account (before insert, before update) {

   //This only handles the first record in the Trigger.new collection
   //But if more than 1 Account initiated this trigger, those additional records
   //will not be processed
   Account acct = Trigger.new[0];
   List&lt;Contact&gt; contacts = [select id, salutation, firstname, lastname, email 
              from Contact where accountId = :acct.Id];
   
}
						</code></pre>
					</section>
					<section>
					<h2>Bulkified Trigger</h2>
					<pre><code data-trim contenteditable><commit_msg>Changed bulkficiation meme<commit_after><!doctype html>
<html lang="en">

	<head>
		<meta charset="utf-8">

		<title>Apex Trigger Development - Best Practices</title>

		<meta name="description" content="Apex Trigger Best Practices">
		<meta name="author" content="<NAME>">

		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">

		<link rel="stylesheet" href="css/reveal.css">
		<link rel="stylesheet" href="css/theme/sky.css" id="theme">

		<!-- Code syntax highlighting -->
		<link rel="stylesheet" href="lib/css/zenburn.css">

		<!-- Printing and PDF exports -->
		<script>
			var link = document.createElement( 'link' );
			link.rel = 'stylesheet';
			link.type = 'text/css';
			link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
			document.getElementsByTagName( 'head' )[0].appendChild( link );
		</script>

		<!--[if lt IE 9]>
		<script src="lib/js/html5shiv.js"></script>
		<![endif]-->
	</head>

	<body>

		<div class="reveal">

			<div class="slides">
				<section>
					<h1>Apex Trigger Development</h1>
					<h3>Best Practices</h3>
					<p><small>Presented by <NAME> / <a href="https://twitter.com/scottbcovert">@scottbcovert</a></small></p>
				</section>

				<section>
					<h2>Intro</h2>
					<p>Umm, my workflow rule can't do that-what should I do?</p>
					<img src="http://memecrunch.com/meme/5942Y/apex-trigger/image.gif?w=500&c=1"/>
				</section>

				<section>
					<section>
						<h2>Common Issues</h2>
						<p>The world of Apex development ain't all sunshine and rainbows.</p>
						<img src="http://cdn.meme.am/instances/500x/36001409.jpg"/>
					</section>
					<section>
						<h2>Context</h2>
						<p>Should my logic live in a before or after trigger?</p>
						<p>Null reference? I thought all records have ids?</p>
					</section>
					<section>
						<h2>Bulk DML Operations</h2>
						<p>Umm, you mean you want to insert more than a single account at once?</p>
					</section>
					<section>
						<h2>SOQL inside For Loops</h2>
						<p>...what's a governor limit?</p>
					</section>
					<section>
						<h2>Logic inside Triggers</h2>
						<p>Unit tests?</p>
					</section>
					<section>
						<h2>Multiple Triggers per Object</h2>
						<img src="http://cdn.meme.am/instances/500x/59330053.jpg"/>
					</section>
					<section>
						<h2>Recursion</h2>
						<img height="550px" src="http://caseelse.net/wp-content/uploads/2008/05/recursionagain.jpg"/>
					</section>
					<section>
						<h2>Spaghetti Code</h2>
						<p>...but it's sorta working</p>
					</section>
				</section>

				<section>
					<section>
						<h2>Best Practices</h2>
						<img height="550px" src="http://www.sqlsoldier.com/wp/wp-content/uploads/2012/02/BestPractices.jpg"/>
					</section>
					<section>
						<h2>Context</h2>
						<p>Before:</p>
						<ul>
							<li>Set/change field values before writing to database</li>
							<li>No Id value yet for Insert triggers</li>
						</ul>
						<p>After:</p>
						<ul>
							<li>Id values can be safely mapped</li>
						</ul>
						<p>Insert:</p>
						<ul>
							<li>No Trigger.old or Trigger.oldMap</li>
						</ul>
						<p>Update:</p>
						<ul>
							<li>Can update original object (be careful of recursion)</li>
						</ul>
					</section>
					<section>
						<h2>Context Cheat Sheets</h2>
						<p><a href="https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm">Trigger Context Variables</a></p>
						<p><a href="https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables_considerations.htm">Context Variable Considerations</a></p>
					</section>
					<section>
						<h2>Bulkification</h2>
						<img src="http://cdn.meme.am/instances/500x/59423891.jpg"/>
					</section>
					<section>
						<h2>Don't Do This!</h2>
						<pre><code data-trim contenteditable>
trigger accountTestTrggr on Account (before insert, before update) {

   //This only handles the first record in the Trigger.new collection
   //But if more than 1 Account initiated this trigger, those additional records
   //will not be processed
   Account acct = Trigger.new[0];
   List&lt;Contact&gt; contacts = [select id, salutation, firstname, lastname, email 
              from Contact where accountId = :acct.Id];
   
}
						</code></pre>
					</section>
					<section>
					<h2>Bulkified Trigger</h2>
					<pre><code data-trim contenteditable>
{'fraction_non_alphanumeric': 0.16774262965353992, 'fraction_numerical': 0.02130406714009038, 'mean_word_length': 2.876146788990826, 'pattern_counts': {'":': 0, '<': 331, '<?xml version=': 0, '>': 331, 'https://': 7, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1483021', 'n_tokens_mistral': 4277, 'n_tokens_neox': 3245, 'n_words': 691}