<?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 for TehNrd</title>
	<atom:link href="http://www.tehnrd.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tehnrd.com</link>
	<description>Force.com - jQuery - Technology - Life</description>
	<lastBuildDate>Wed, 08 Sep 2010 01:23:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>Comment on IP Address Geolocation with Force.com by Rajesh</title>
		<link>http://www.tehnrd.com/ip-address-geolocation-with-force-com/comment-page-1/#comment-1857</link>
		<dc:creator>Rajesh</dc:creator>
		<pubDate>Wed, 08 Sep 2010 01:23:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.tehnrd.com/?p=808#comment-1857</guid>
		<description>Cool</description>
		<content:encoded><![CDATA[<p>Cool</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Dear Apple: Please Add Image Stabilization to iPhone Video by Eric</title>
		<link>http://www.tehnrd.com/dear-apple-please-add-image-stabilization-to-iphone-video/comment-page-1/#comment-1752</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Tue, 31 Aug 2010 14:35:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.tehnrd.com/?p=749#comment-1752</guid>
		<description>The gyroscope must be used, there couldn&#039;t be a more appropriate tool on the iPhone to solve this problem.</description>
		<content:encoded><![CDATA[<p>The gyroscope must be used, there couldn&#8217;t be a more appropriate tool on the iPhone to solve this problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Getter Method Order and Visualforce Pages by lodoss118</title>
		<link>http://www.tehnrd.com/getter-method-order-and-visualforce-pages/comment-page-1/#comment-1706</link>
		<dc:creator>lodoss118</dc:creator>
		<pubDate>Sat, 28 Aug 2010 11:08:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.tehnrd.com/?p=804#comment-1706</guid>
		<description>why not just use

if(a.NumberOfEmployees &gt; 5){
    ApexPages.addMessage(new ApexMessage(WARNING, &#039;OMG&#039;));
}</description>
		<content:encoded><![CDATA[<p>why not just use</p>
<p>if(a.NumberOfEmployees &gt; 5){<br />
    ApexPages.addMessage(new ApexMessage(WARNING, &#8216;OMG&#8217;));<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Getter Method Order and Visualforce Pages by Stephan Morais</title>
		<link>http://www.tehnrd.com/getter-method-order-and-visualforce-pages/comment-page-1/#comment-1699</link>
		<dc:creator>Stephan Morais</dc:creator>
		<pubDate>Fri, 27 Aug 2010 16:30:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.tehnrd.com/?p=804#comment-1699</guid>
		<description>One think to note is that execution order for setters and getters is called out in the docs:

http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_compref_additional_controller.htm</description>
		<content:encoded><![CDATA[<p>One think to note is that execution order for setters and getters is called out in the docs:</p>
<p><a href="http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_compref_additional_controller.htm" rel="nofollow">http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_compref_additional_controller.htm</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Getter Method Order and Visualforce Pages by Ralph Callaway</title>
		<link>http://www.tehnrd.com/getter-method-order-and-visualforce-pages/comment-page-1/#comment-1677</link>
		<dc:creator>Ralph Callaway</dc:creator>
		<pubDate>Wed, 25 Aug 2010 16:39:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.tehnrd.com/?p=804#comment-1677</guid>
		<description>Great post.  Ahh, the idiosyncrasies of Apex and VisualForce.

In truth, for any language you should design your getters so that you don&#039;t need to depend on execution order, primarily because execution order bugs are so darn hard to debug, and let&#039;s not start on their tendency to arise and disappear spontaneously!!

Personally I would:
1) Take advantage of the fact any time you reference a property (accounts in this case) in your controller it runs the getter method (avoiding any execution order issues)
2) Keep the show warning logic in it&#039;s own setter method (each function has one purpose which makes it easier to understand)

&lt;code&gt;
public class GetOrderFix {
 
	// do I have any accounts with more than 5 employees
	public Boolean showLargeAcctWarning {
 		get {
 			// the getter method for &#039;accounts&#039; will run when &#039;accounts&#039; is refererence
			for(Account a : accounts){
				if(a.NumberOfEmployees &gt; 5)
					return true;
			} 
		}
		private set;
 	}
 
	public List accounts {
		get {
			if(accounts == null) {
				accounts = [Select Id, Name, NumberOfEmployees from Account limit 5];	
			}
			return accounts;
		}
		set;
	}
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Great post.  Ahh, the idiosyncrasies of Apex and VisualForce.</p>
<p>In truth, for any language you should design your getters so that you don&#8217;t need to depend on execution order, primarily because execution order bugs are so darn hard to debug, and let&#8217;s not start on their tendency to arise and disappear spontaneously!!</p>
<p>Personally I would:<br />
1) Take advantage of the fact any time you reference a property (accounts in this case) in your controller it runs the getter method (avoiding any execution order issues)<br />
2) Keep the show warning logic in it&#8217;s own setter method (each function has one purpose which makes it easier to understand)</p>
<p><code><br />
public class GetOrderFix {</p>
<p>	// do I have any accounts with more than 5 employees<br />
	public Boolean showLargeAcctWarning {<br />
 		get {<br />
 			// the getter method for 'accounts' will run when 'accounts' is refererence<br />
			for(Account a : accounts){<br />
				if(a.NumberOfEmployees &gt; 5)<br />
					return true;<br />
			}<br />
		}<br />
		private set;<br />
 	}</p>
<p>	public List accounts {<br />
		get {<br />
			if(accounts == null) {<br />
				accounts = [Select Id, Name, NumberOfEmployees from Account limit 5];<br />
			}<br />
			return accounts;<br />
		}<br />
		set;<br />
	}<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Getter Method Order and Visualforce Pages by Scott Hemmeter</title>
		<link>http://www.tehnrd.com/getter-method-order-and-visualforce-pages/comment-page-1/#comment-1674</link>
		<dc:creator>Scott Hemmeter</dc:creator>
		<pubDate>Wed, 25 Aug 2010 15:51:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.tehnrd.com/?p=804#comment-1674</guid>
		<description>Nice post.  In your analysis, did you find out anything about when static code runs vs. the constructor?

For example, just for readability, I often do my variables like this.

public Boolean someFlag {get; set;} {someFlag = false;}

It all should run before the page loads and, as long as I don&#039;t depend on the someFlag variable inside the constructor, I should be ok.  However, just wondering if you came across any quirks.</description>
		<content:encoded><![CDATA[<p>Nice post.  In your analysis, did you find out anything about when static code runs vs. the constructor?</p>
<p>For example, just for readability, I often do my variables like this.</p>
<p>public Boolean someFlag {get; set;} {someFlag = false;}</p>
<p>It all should run before the page loads and, as long as I don&#8217;t depend on the someFlag variable inside the constructor, I should be ok.  However, just wondering if you came across any quirks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Getter Method Order and Visualforce Pages by Jeff Douglas</title>
		<link>http://www.tehnrd.com/getter-method-order-and-visualforce-pages/comment-page-1/#comment-1672</link>
		<dc:creator>Jeff Douglas</dc:creator>
		<pubDate>Wed, 25 Aug 2010 13:21:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.tehnrd.com/?p=804#comment-1672</guid>
		<description>I love these little &quot;features&quot; of Apex and Visualforce. They make developing and debugging fun! Not sure how many hours I&#039;ve wasted tracking down issues like this.</description>
		<content:encoded><![CDATA[<p>I love these little &#8220;features&#8221; of Apex and Visualforce. They make developing and debugging fun! Not sure how many hours I&#8217;ve wasted tracking down issues like this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Getter Method Order and Visualforce Pages by Jason</title>
		<link>http://www.tehnrd.com/getter-method-order-and-visualforce-pages/comment-page-1/#comment-1663</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Tue, 24 Aug 2010 21:14:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.tehnrd.com/?p=804#comment-1663</guid>
		<description>@Michael, the method will be called twice but the query will only execute once as it checks to see if the list is null and only proceeds if it is.

@Peter C, I think this adds a bit to much complexity for my liking. It can easily become a giant spaghetti mess when getters start calling getters.

There are many different ways to approach this problem. One of the reasons I ran into the problem above was at the time there were no apex properties which can greatly simplify getting and setting. Another solution, and what I would probably do today is something similar to this:

&lt;pre lang=&quot;java&quot;&gt;
public class GetOrderFix{
	
	public Boolean showLargeAcctWarning{get; set;}
	public List&lt;Account&gt; accts {get; set;}

	public GetOrderFix(){ 
		buildAcctList();
	}

	public void buildAcctList(){
		accts = new List&lt;Account&gt;();

		for(Account a : [Select Id, Name, NumberOfEmployees from Account limit 5]){
			accts.add(a);
			if(a.NumberOfEmployees &gt; 5){
				showLargeAcctWarning = true;
			}
		}
		return accts;
	}
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>@Michael, the method will be called twice but the query will only execute once as it checks to see if the list is null and only proceeds if it is.</p>
<p>@Peter C, I think this adds a bit to much complexity for my liking. It can easily become a giant spaghetti mess when getters start calling getters.</p>
<p>There are many different ways to approach this problem. One of the reasons I ran into the problem above was at the time there were no apex properties which can greatly simplify getting and setting. Another solution, and what I would probably do today is something similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GetOrderFix<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Boolean</span> showLargeAcctWarning<span style="color: #009900;">&#123;</span>get<span style="color: #339933;">;</span> set<span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Account<span style="color: #339933;">&gt;</span> accts <span style="color: #009900;">&#123;</span>get<span style="color: #339933;">;</span> set<span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> GetOrderFix<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
		buildAcctList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> buildAcctList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		accts <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> List<span style="color: #339933;">&lt;</span>Account<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Account a <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>Select Id, <span style="color: #003399;">Name</span>, NumberOfEmployees from Account limit <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			accts.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>a.<span style="color: #006633;">NumberOfEmployees</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				showLargeAcctWarning <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> accts<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>Comment on Getter Method Order and Visualforce Pages by Rob</title>
		<link>http://www.tehnrd.com/getter-method-order-and-visualforce-pages/comment-page-1/#comment-1660</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Tue, 24 Aug 2010 20:33:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.tehnrd.com/?p=804#comment-1660</guid>
		<description>Nice.  This sounds like a classic compile-time vs run-time binding quiz, except with &quot;page generation time&quot; instead of &quot;compile time&quot;.</description>
		<content:encoded><![CDATA[<p>Nice.  This sounds like a classic compile-time vs run-time binding quiz, except with &#8220;page generation time&#8221; instead of &#8220;compile time&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Getter Method Order and Visualforce Pages by Peter C</title>
		<link>http://www.tehnrd.com/getter-method-order-and-visualforce-pages/comment-page-1/#comment-1658</link>
		<dc:creator>Peter C</dc:creator>
		<pubDate>Tue, 24 Aug 2010 20:03:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.tehnrd.com/?p=804#comment-1658</guid>
		<description>Question - is it more efficient to add the getAccounts() to the constructor, or could you just define an explicit getter method for the showLargeAccountWarning, and then have that getter call the getAccounts() method? That way, you know getaccounts is called before it returns the Boolean value, so it would always be set...?</description>
		<content:encoded><![CDATA[<p>Question &#8211; is it more efficient to add the getAccounts() to the constructor, or could you just define an explicit getter method for the showLargeAccountWarning, and then have that getter call the getAccounts() method? That way, you know getaccounts is called before it returns the Boolean value, so it would always be set&#8230;?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
