<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>X-Squared On-Demand &#187; Summer 09</title>
	<atom:link href="http://www.x2od.com/cat/salesforce/editions/160/feed" rel="self" type="application/rss+xml" />
	<link>http://www.x2od.com</link>
	<description>Salesforce Configuration, Administration, and Development</description>
	<lastBuildDate>Fri, 11 Jun 2010 16:30:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Pulling Code Out of Triggers</title>
		<link>http://www.x2od.com/2009/05/18/pulling-code-out-of-triggers.html</link>
		<comments>http://www.x2od.com/2009/05/18/pulling-code-out-of-triggers.html#comments</comments>
		<pubDate>Mon, 18 May 2009 17:00:41 +0000</pubDate>
		<dc:creator>David Schach</dc:creator>
				<category><![CDATA[Apex]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Summer 09]]></category>
		<category><![CDATA[salesforce.com]]></category>
		<category><![CDATA[Eclipse IDE]]></category>
		<category><![CDATA[Force.com Platform]]></category>

		<guid isPermaLink="false">http://www.x2od.com/?p=583</guid>
		<description><![CDATA[To date, triggers have only been accessible on each object's setup page, leading to a lot of hunting for code within the Salesforce CRM application. Even in Eclipse, switching between the Class and Trigger folders for a given project can be a pain.

These pains can partially be alleviated by keeping all Apex code in one place--as Apex Classes.

Read more: http://www.x2od.com/?p=583&#038;preview=true#ixzz0FncHsqPw&#038;B]]></description>
			<content:encoded><![CDATA[<p>To date, triggers have only been accessible on each object's setup page, leading to a lot of hunting for code within the Salesforce CRM application.  Even in Eclipse, switching between the Class and Trigger folders for a given project can be a pain.</p>
<p>These pains can partially be alleviated by keeping all Apex code in one place--as Apex Classes.  With the addition of a consolidated trigger list in <a href="http://wiki.developerforce.com/index.php/Summer_09">Summer09</a>, some may feel that this post is superfluous, but consolidating code in one place, combined with the trigger list, will lead to a better development, debugging, and org administration experience.</p>

<p>First, here's a sample trigger (written by <a href="http://blog.jeffdouglas.com/2009/04/20/writing-bulk-triggers-for-salesforce">Jeff Douglas</a>):</p>
<pre class="brush: java;">
trigger AddOwnerColor on Account (before insert, before update) {

    // create a set of all the unique ownerIds
    Set&amp;lt;Id&amp;gt; ownerIds = new Set&amp;lt;Id&amp;gt;();
    for (Account a : Trigger.new)
        ownerIds.add(a.OwnerId);    

    // query for all the User records for the unique userIds in the records
    // create a map for a lookup / hash table for the user info
    Map&amp;lt;Id, User&amp;gt; owners = new Map&amp;lt;Id, User&amp;gt;([Select Favorite_Color__c from User Where Id in: ownerIds]);   

    // iterate over the list of records being processed in the trigger and
    // set the color before being inserted or updated
    for (Account a : Trigger.new)
        a.Owner_Favorite_Color__c = owners.get(a.OwnerId).Favorite_Color__c; 
}
</pre>
<p>Let's pull the code from the trigger into an Apex Class and leave a reference to that class & method in the trigger.  We need to pass the list Trigger.new as a parameter to the new class's method:<p>
The trigger:
<pre class="brush: java;">
trigger AddOwnerColor on Account (before insert, before update) {
AccountTriggers.AddOwnerColor(Trigger.new);
}
</pre>
And the class:
<pre class="brush: java;">
public class AccountTriggers {
    public static void AddOwnerColor(Account[] accts) {

    // create a set of all the unique ownerIds
    Set&amp;lt;Id&amp;gt; ownerIds = new Set&amp;lt;Id&amp;gt;();
    for (Account a : accts)
        ownerIds.add(a.OwnerId);    

    // query for all the User records for the unique userIds in the records
    // create a map for a lookup / hash table for the user info
    Map&amp;lt;Id, User&amp;gt; owners = new Map&amp;lt;Id, User&amp;gt;([Select Favorite_Color__c from User Where Id in: ownerIds]);   

    // iterate over the list of records being processed in the trigger and
    // set the color before being inserted or updated
    for (Account a : accts)
        a.Owner_Favorite_Color__c = owners.get(a.OwnerId).Favorite_Color__c; 
    } // close AddOwnerColor
}
</pre>
While this may seem trivial, it has a few advantages:<p>
<ul>
	<li>Easier to work in Eclipse (all code in the Classes section)</li>
	<li>Easier to write test code (can see tests and their associated methods in one place)</li>
	<li>Can promote code reuse by allowing other classes and triggers to call the same method.</li>
	<li>For those who like to include test code in the same class as the regular Class, this allows them to do so.</li>
</ul>
<p>There's a catch (there always is):
<p>You should comment into your Class which trigger is calling the class because otherwise, it is almost impossible to see at a glance where the code flows.  This will especially help when writing and debugging tests.
<p>Just a matter of personal style: It may be a good idea to write an Apex Class for each object's triggers (such as class AccountTriggers above).  Code reuse is still possible, but it can track where triggers were originally used.
<p>Happy coding!]]></content:encoded>
			<wfw:commentRss>http://www.x2od.com/2009/05/18/pulling-code-out-of-triggers.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dashboards are Improved AND New in Summer 09</title>
		<link>http://www.x2od.com/2009/05/07/dashboards-are-improved-and-new-in-summer-09.html</link>
		<comments>http://www.x2od.com/2009/05/07/dashboards-are-improved-and-new-in-summer-09.html#comments</comments>
		<pubDate>Thu, 07 May 2009 21:54:18 +0000</pubDate>
		<dc:creator>David Schach</dc:creator>
				<category><![CDATA[Configuration]]></category>
		<category><![CDATA[Native Application]]></category>
		<category><![CDATA[New Features]]></category>
		<category><![CDATA[Summer 09]]></category>
		<category><![CDATA[salesforce.com]]></category>
		<category><![CDATA[Force.com Builder]]></category>
		<category><![CDATA[Salesforce.com]]></category>

		<guid isPermaLink="false">http://www.x2od.com/?p=509</guid>
		<description><![CDATA[The Summer09 prerelease orgs are here, so <a href="https://prerelwww.pre.salesforce.com/form/trial/prerelease_summer09.jsp">get yours now</a>!  Upon first look, something cool stood out and merits immediate posting:

Dashboards are improved.  The colors are more vivid, there's detail in the bars and pie chart wedges, and... pie charts can now display the actual and percentage values!]]></description>
			<content:encoded><![CDATA[<p>The Summer09 prerelease orgs are here, so <a href="https://prerelwww.pre.salesforce.com/form/trial/prerelease_summer09.jsp">get yours now</a>!  Upon first look, something cool stood out and merits immediate posting:</p>
<p>Dashboards are improved.  The colors are more vivid, there&#8217;s detail in the bars and pie chart wedges, and&#8230; pie charts can now display the actual <em>and</em> percentage values!</p>
<p>Dashboards are also new.  Visualforce pages can now be included as dashboard components, and there&#8217;s a new &#8220;Color-Blind Palette on Charts&#8221; setting for each user.  Here are before and after shots.</p>
<div id="attachment_507" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.x2od.com/wp/uploads/dashboard-regular.jpg"><img src="http://www.x2od.com/wp/uploads/dashboard-regular-300x168.jpg" alt="Dashboard with regular color scheme" title="dashboard-regular" width="300" height="168" class="size-medium wp-image-507" /></a><p class="wp-caption-text">Salesforce dashboard with regular color scheme</p></div>
<div id="attachment_508" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.x2od.com/wp/uploads/dashboard-cb.jpg"><img src="http://www.x2od.com/wp/uploads/dashboard-cb-300x224.jpg" alt="Salesforce dashboard with color-blind/alternate color scheme" title="dashboard-cb" width="300" height="224" class="size-medium wp-image-508"  /></a><p class="wp-caption-text">Dashboard with color-blind/alternate color scheme</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.x2od.com/2009/05/07/dashboards-are-improved-and-new-in-summer-09.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
