<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Two interesting ways to architect Apex triggers</title>
	<atom:link href="http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/feed" rel="self" type="application/rss+xml" />
	<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers</link>
	<description></description>
	<lastBuildDate>Tue, 29 Nov 2011 19:15:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: NPO Triggers 101 - Kevin Bromer</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-342205</link>
		<dc:creator>NPO Triggers 101 - Kevin Bromer</dc:creator>
		<pubDate>Wed, 08 Jun 2011 21:54:53 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-342205</guid>
		<description>[...] This is by no means a gentle 101 introduction. Writing code can be tough but incredibly rewarding, not to mention efficient in many cases! Salesforce actually makes it alot easier than it used to be by providing you with some great tools and abstractions to make the job just a tad more intuitive. Hopefully this will empower/inspire you to dive in and get your hands a little dirty. Here’s a quick secret: I was a political science major as an undergrad. Like many people, learned how to code by diving in head first, chewing through tons of test environments, and occasionally (okay, often) crashing the family computer in my younger years (nice thing about Salesforce? Can’t crash your computer anymore :)). The great thing about a sandbox is you don’t need to worry, its there for you to play in and learn the ropes, so don’t be intimated by what we’ve worked through. I’d also encourage you to read some more about triggers, including some best practices around architecture. [...]</description>
		<content:encoded><![CDATA[<p>[...] This is by no means a gentle 101 introduction. Writing code can be tough but incredibly rewarding, not to mention efficient in many cases! Salesforce actually makes it alot easier than it used to be by providing you with some great tools and abstractions to make the job just a tad more intuitive. Hopefully this will empower/inspire you to dive in and get your hands a little dirty. Here’s a quick secret: I was a political science major as an undergrad. Like many people, learned how to code by diving in head first, chewing through tons of test environments, and occasionally (okay, often) crashing the family computer in my younger years (nice thing about Salesforce? Can’t crash your computer anymore <img src='http://gokubi.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ). The great thing about a sandbox is you don’t need to worry, its there for you to play in and learn the ropes, so don’t be intimated by what we’ve worked through. I’d also encourage you to read some more about triggers, including some best practices around architecture. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Best practice: architect Apex triggers - Cloud Giga at Cloud Giga</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-309381</link>
		<dc:creator>Best practice: architect Apex triggers - Cloud Giga at Cloud Giga</dc:creator>
		<pubDate>Mon, 28 Mar 2011 14:07:33 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-309381</guid>
		<description>[...] gokubi and jonathanrico have good posts about how to write Apex trigger codes in a best practice [...]</description>
		<content:encoded><![CDATA[<p>[...] gokubi and jonathanrico have good posts about how to write Apex trigger codes in a best practice [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Interesting ways of architecting Apex Triggers &#171; jonathanrico.</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-206270</link>
		<dc:creator>Interesting ways of architecting Apex Triggers &#171; jonathanrico.</dc:creator>
		<pubDate>Tue, 26 Jan 2010 05:55:02 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-206270</guid>
		<description>[...] came across a blog post at gokubi.com (http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers) about some interesting ways of architecting Apex [...]</description>
		<content:encoded><![CDATA[<p>[...] came across a blog post at gokubi.com (<a href="http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers" rel="nofollow">http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers</a>) about some interesting ways of architecting Apex [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wes</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-191514</link>
		<dc:creator>Wes</dc:creator>
		<pubDate>Tue, 29 Sep 2009 16:03:23 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-191514</guid>
		<description>Building on Jon&#039;s idea why not make the trigger type available as method a parameter and/or return type? That way frameworks could be developed and triggers would have tiny implementations.

In the Mike vs George debate I&#039;d side with Mike. I&#039;d disagree with static classes being more easy to maintain. A clean OO class architecture will always win out on the maintainability debate mostly because of potential class hiearchies coupled with good ol&#039; polymorphism. 

That said I am a fan of static classes, but would usually use them in utility classes or architectures that subscribe to factory patterns e.g. If I were using an enum as you have above I might&#039;ve declared it as static in a utility class.</description>
		<content:encoded><![CDATA[<p>Building on Jon&#8217;s idea why not make the trigger type available as method a parameter and/or return type? That way frameworks could be developed and triggers would have tiny implementations.</p>
<p>In the Mike vs George debate I&#8217;d side with Mike. I&#8217;d disagree with static classes being more easy to maintain. A clean OO class architecture will always win out on the maintainability debate mostly because of potential class hiearchies coupled with good ol&#8217; polymorphism. </p>
<p>That said I am a fan of static classes, but would usually use them in utility classes or architectures that subscribe to factory patterns e.g. If I were using an enum as you have above I might&#8217;ve declared it as static in a utility class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Leach</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-189480</link>
		<dc:creator>Mike Leach</dc:creator>
		<pubDate>Tue, 08 Sep 2009 19:39:23 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-189480</guid>
		<description>It&#039;s always convenient when a static method pops up in autocomplete (or Intellisense) and always worth exploring.

Thread safety is really the only issue to review when using static methods. Assuming the static method is not dependent on any globally scoped objects, then either approach is fine.</description>
		<content:encoded><![CDATA[<p>It&#8217;s always convenient when a static method pops up in autocomplete (or Intellisense) and always worth exploring.</p>
<p>Thread safety is really the only issue to review when using static methods. Assuming the static method is not dependent on any globally scoped objects, then either approach is fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gokubi.com &#187; Blog Archive &#187; Apex Architecture</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-189465</link>
		<dc:creator>gokubi.com &#187; Blog Archive &#187; Apex Architecture</dc:creator>
		<pubDate>Tue, 08 Sep 2009 16:55:37 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-189465</guid>
		<description>[...] gokubi.com       &#171; Two interesting ways to architect Apex triggers [...]</description>
		<content:encoded><![CDATA[<p>[...] gokubi.com       &laquo; Two interesting ways to architect Apex triggers [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: George Scott</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-189318</link>
		<dc:creator>George Scott</dc:creator>
		<pubDate>Sun, 06 Sep 2009 19:07:11 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-189318</guid>
		<description>Mike&#039;s approach is definitely the more object-oriented approach and a cleaner design from that perspective.

There are a couple of reasons I would use static methods over the object-oriented approach: maintenance and performance.  

If a lot of people will be editing the code over time (maintenance) and some of them are not professional programmers, it is sometimes best not to introduce object-oriented concepts if they are not needed.  This really depends on the skill set of those maintaing the code.

On the performance side, creating an object has a cost associated with it, both in terms of creation, and later when it has to be garbage-collected by the system.  So I tend to avoid creating temporary objects if I can avoid it.  This is just a habit after years of tuning server-side Java code, and may not be relevant for Apex.</description>
		<content:encoded><![CDATA[<p>Mike&#8217;s approach is definitely the more object-oriented approach and a cleaner design from that perspective.</p>
<p>There are a couple of reasons I would use static methods over the object-oriented approach: maintenance and performance.  </p>
<p>If a lot of people will be editing the code over time (maintenance) and some of them are not professional programmers, it is sometimes best not to introduce object-oriented concepts if they are not needed.  This really depends on the skill set of those maintaing the code.</p>
<p>On the performance side, creating an object has a cost associated with it, both in terms of creation, and later when it has to be garbage-collected by the system.  So I tend to avoid creating temporary objects if I can avoid it.  This is just a habit after years of tuning server-side Java code, and may not be relevant for Apex.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-189306</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Sun, 06 Sep 2009 15:17:55 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-189306</guid>
		<description>George, I&#039;ve never gotten my head around when I should chose a static implementation, and when I should make the class one that gets instantiated. In this case, it seems like I Mike&#039;s idea to instantiate and then call individual methods is pretty efficient. In the constructor we can grab the two trigger sets into local variables for use later in the other methods.

It keeps the signatures of the methods clean, but they can only be called when the class has been instantiated.

Would love to hear your thoughts on static vs. instantiated in this case.

Thanks for all the great comments everyone!</description>
		<content:encoded><![CDATA[<p>George, I&#8217;ve never gotten my head around when I should chose a static implementation, and when I should make the class one that gets instantiated. In this case, it seems like I Mike&#8217;s idea to instantiate and then call individual methods is pretty efficient. In the constructor we can grab the two trigger sets into local variables for use later in the other methods.</p>
<p>It keeps the signatures of the methods clean, but they can only be called when the class has been instantiated.</p>
<p>Would love to hear your thoughts on static vs. instantiated in this case.</p>
<p>Thanks for all the great comments everyone!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-189257</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Sat, 05 Sep 2009 21:10:40 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-189257</guid>
		<description>That&#039;s an interesting take on it Mike. It&#039;s similar to George&#039;s example but passes the sets in the controller. I like that as then you&#039;re only handling them once, and then each method can process those sets appropriately.</description>
		<content:encoded><![CDATA[<p>That&#8217;s an interesting take on it Mike. It&#8217;s similar to George&#8217;s example but passes the sets in the controller. I like that as then you&#8217;re only handling them once, and then each method can process those sets appropriately.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-189256</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Sat, 05 Sep 2009 21:08:47 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-189256</guid>
		<description>Thanks for that example George. Static calls make sense, and seem to in this case. Thanks.</description>
		<content:encoded><![CDATA[<p>Thanks for that example George. Static calls make sense, and seem to in this case. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Leach</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-189244</link>
		<dc:creator>Mike Leach</dc:creator>
		<pubDate>Sat, 05 Sep 2009 18:29:17 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-189244</guid>
		<description>On second thought, I&#039;d probably prefer calling unique (possibly abstract) methods for each event type in the Factory container.

MyObjectClass process = new MyObjectClass(Trigger.new, Trigger.old);

//switch or if statement block
process.OnBeforeInsert();
process.OnAfterInsert();
process.OnBeforeUpdate();
process.OnAfterInsert();


Microsoft really killed their Win32 API with too many macros/structs/enums. .NET corrected this mistake.</description>
		<content:encoded><![CDATA[<p>On second thought, I&#8217;d probably prefer calling unique (possibly abstract) methods for each event type in the Factory container.</p>
<p>MyObjectClass process = new MyObjectClass(Trigger.new, Trigger.old);</p>
<p>//switch or if statement block<br />
process.OnBeforeInsert();<br />
process.OnAfterInsert();<br />
process.OnBeforeUpdate();<br />
process.OnAfterInsert();</p>
<p>Microsoft really killed their Win32 API with too many macros/structs/enums. .NET corrected this mistake.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: George Scott</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-189243</link>
		<dc:creator>George Scott</dc:creator>
		<pubDate>Sat, 05 Sep 2009 17:58:25 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-189243</guid>
		<description>Interesting post Steve.  I&#039;m always curious about different design patterns for Apex code.

Being a long time Java programmer, I have one question for you.  Is there any reason you are performing the logic in a constructor versus a public static method in the class?  This is the approach I typically use, no need for enums or multiple classes.  For example:

if(Trigger.isInsert &amp;&amp; Trigger.isBefore){
   MyObjectClass.beforeInsert(Trigger.new, Trigger.old);
}
else if (Trigger.isAfter &amp;&amp; Trigger.isInsert ){
   MyObjectClass.afterInsert(Trigger.new, Trigger.old);
}
...

In the MyObjectClass you just define the methods as static so they can be called without an object instance:

public class MyObjectClass {

  public static void beforeInsert(MyObject__c[] myObjects, MyObject__c[] myOldObjects) {
    ...
  }

  pubilc static void afterInsert(MyObject__c[] myObjects, MyObject__c[] myOldObjects) {
    ...
  }</description>
		<content:encoded><![CDATA[<p>Interesting post Steve.  I&#8217;m always curious about different design patterns for Apex code.</p>
<p>Being a long time Java programmer, I have one question for you.  Is there any reason you are performing the logic in a constructor versus a public static method in the class?  This is the approach I typically use, no need for enums or multiple classes.  For example:</p>
<p>if(Trigger.isInsert &amp;&amp; Trigger.isBefore){<br />
   MyObjectClass.beforeInsert(Trigger.new, Trigger.old);<br />
}<br />
else if (Trigger.isAfter &amp;&amp; Trigger.isInsert ){<br />
   MyObjectClass.afterInsert(Trigger.new, Trigger.old);<br />
}<br />
&#8230;</p>
<p>In the MyObjectClass you just define the methods as static so they can be called without an object instance:</p>
<p>public class MyObjectClass {</p>
<p>  public static void beforeInsert(MyObject__c[] myObjects, MyObject__c[] myOldObjects) {<br />
    &#8230;<br />
  }</p>
<p>  pubilc static void afterInsert(MyObject__c[] myObjects, MyObject__c[] myOldObjects) {<br />
    &#8230;<br />
  }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-189236</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Sat, 05 Sep 2009 16:01:52 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-189236</guid>
		<description>Great idea Jon.

There are two pieces of data: operation and type. Operation would be an enum for the DML operation, Type could be before or after. Type could be an enum. Or you could just use the isBefore boolean.

Trigger.Operation enum and Trigger.Type enum (or the current Trigger.isBefore)

Or you could flatten everything into Trigger.Action, an enum that would combine the two values to &quot;Before Insert&quot; and &quot;After Insert&quot;, etc.

 Sounds like we need an idea.</description>
		<content:encoded><![CDATA[<p>Great idea Jon.</p>
<p>There are two pieces of data: operation and type. Operation would be an enum for the DML operation, Type could be before or after. Type could be an enum. Or you could just use the isBefore boolean.</p>
<p>Trigger.Operation enum and Trigger.Type enum (or the current Trigger.isBefore)</p>
<p>Or you could flatten everything into Trigger.Action, an enum that would combine the two values to &#8220;Before Insert&#8221; and &#8220;After Insert&#8221;, etc.</p>
<p> Sounds like we need an idea.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Leach</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-189235</link>
		<dc:creator>Mike Leach</dc:creator>
		<pubDate>Sat, 05 Sep 2009 15:56:27 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-189235</guid>
		<description>Good question. Why is the public enum declared twice? Does Apex not support global namespace scope?</description>
		<content:encoded><![CDATA[<p>Good question. Why is the public enum declared twice? Does Apex not support global namespace scope?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Mountjoy</title>
		<link>http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggers/comment-page-1#comment-189233</link>
		<dc:creator>Jon Mountjoy</dc:creator>
		<pubDate>Sat, 05 Sep 2009 15:29:05 +0000</pubDate>
		<guid isPermaLink="false">http://gokubi.com/?p=906#comment-189233</guid>
		<description>It strikes me that what is really needed here, to induce the DRY principle, is to have the type of trigger (result of Trigger.isInsert, Trigger.isAfter etc.) available as an Enum in the first place. Perhaps an Idea is called for?  Something like: Trigger.triggerAction.  Otherwise the skeleton code you have in the second case is going to repeated for each different trigger you write - and worse, you have no alternative but to repeat it.</description>
		<content:encoded><![CDATA[<p>It strikes me that what is really needed here, to induce the DRY principle, is to have the type of trigger (result of Trigger.isInsert, Trigger.isAfter etc.) available as an Enum in the first place. Perhaps an Idea is called for?  Something like: Trigger.triggerAction.  Otherwise the skeleton code you have in the second case is going to repeated for each different trigger you write &#8211; and worse, you have no alternative but to repeat it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

