<?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: List has no rows for assignment to SObject</title>
	<atom:link href="http://theEnforcer.net/2009/09/list-has-no-rows-for-assignment-to-sobject/feed/" rel="self" type="application/rss+xml" />
	<link>http://theEnforcer.net/2009/09/list-has-no-rows-for-assignment-to-sobject/</link>
	<description>a force.com blog</description>
	<lastBuildDate>Thu, 12 Apr 2012 17:58:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
	<item>
		<title>By: Kim Bailey</title>
		<link>http://theEnforcer.net/2009/09/list-has-no-rows-for-assignment-to-sobject/comment-page-1/#comment-71490</link>
		<dc:creator>Kim Bailey</dc:creator>
		<pubDate>Thu, 12 Apr 2012 17:58:23 +0000</pubDate>
		<guid isPermaLink="false">http://theEnforcer.net/?p=122#comment-71490</guid>
		<description>HELP! I need to fix this code so I can deploy a change set in our production instance but have NO idea what to change - can anyone suggest code for this:

 static testMethod void testSave() {         
        // Modify the test to query for a portal user that exists in your org
        User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId  null AND UserType=&#039;CustomerSuccess&#039; LIMIT 1];
        System.assert(existingPortalUser != null, &#039;This test depends on an existing test portal user to run&#039;);</description>
		<content:encoded><![CDATA[<p>HELP! I need to fix this code so I can deploy a change set in our production instance but have NO idea what to change &#8211; can anyone suggest code for this:</p>
<p> static testMethod void testSave() {<br />
        // Modify the test to query for a portal user that exists in your org<br />
        User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId  null AND UserType='CustomerSuccess' LIMIT 1];<br />
        System.assert(existingPortalUser != null, &#8216;This test depends on an existing test portal user to run&#8217;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jorma Soucey</title>
		<link>http://theEnforcer.net/2009/09/list-has-no-rows-for-assignment-to-sobject/comment-page-1/#comment-71043</link>
		<dc:creator>Jorma Soucey</dc:creator>
		<pubDate>Fri, 09 Oct 2009 18:36:23 +0000</pubDate>
		<guid isPermaLink="false">http://theEnforcer.net/?p=122#comment-71043</guid>
		<description>Whenever possible, it&#039;s best to try to fit a query that could return nothing inside a try--&gt;catch pair:

Player__c[] players = new Player__c[]();
try{
players = [SELECT Id from Player__c where Name = :username];}
catch {system.queryexception players){
return;
}

This avoids both the runtime error and the null reference.</description>
		<content:encoded><![CDATA[<p>Whenever possible, it&#8217;s best to try to fit a query that could return nothing inside a try&#8211;&gt;catch pair:</p>
<p>Player__c[] players = new Player__c[]();<br />
try{<br />
players = [SELECT Id from Player__c where Name = :username];}<br />
catch {system.queryexception players){<br />
return;<br />
}</p>
<p>This avoids both the runtime error and the null reference.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Vanhook</title>
		<link>http://theEnforcer.net/2009/09/list-has-no-rows-for-assignment-to-sobject/comment-page-1/#comment-71042</link>
		<dc:creator>Richard Vanhook</dc:creator>
		<pubDate>Fri, 09 Oct 2009 17:10:25 +0000</pubDate>
		<guid isPermaLink="false">http://theEnforcer.net/?p=122#comment-71042</guid>
		<description>My safeguard around this issue is to just wrap a try/catch - so line 2 above would become:

Contact c1 = null;
try{
    c1=[SELECT Id FROM Contact LIMIT 1];
}catch(QueryException e){}
if(c1 != null){
    //do something
} else {
    //or gracefully handle no contact found
}</description>
		<content:encoded><![CDATA[<p>My safeguard around this issue is to just wrap a try/catch &#8211; so line 2 above would become:</p>
<p>Contact c1 = null;<br />
try{<br />
    c1=[SELECT Id FROM Contact LIMIT 1];<br />
}catch(QueryException e){}<br />
if(c1 != null){<br />
    //do something<br />
} else {<br />
    //or gracefully handle no contact found<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wes</title>
		<link>http://theEnforcer.net/2009/09/list-has-no-rows-for-assignment-to-sobject/comment-page-1/#comment-71041</link>
		<dc:creator>Wes</dc:creator>
		<pubDate>Fri, 09 Oct 2009 13:53:59 +0000</pubDate>
		<guid isPermaLink="false">http://theEnforcer.net/?p=122#comment-71041</guid>
		<description>I&#039;ve debated with myself how to handle this sort of thing before, I blogged about it some time ago but I prefer to use a single var and surround it with a try-catch (http://developinthecloud.wordpress.com/2009/07/09/handling-system-queryexception/). Of course your method and a try-catch are simply the same thing implemented differently:) Good article.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve debated with myself how to handle this sort of thing before, I blogged about it some time ago but I prefer to use a single var and surround it with a try-catch (<a href="http://developinthecloud.wordpress.com/2009/07/09/handling-system-queryexception/" rel="nofollow">http://developinthecloud.wordpress.com/2009/07/09/handling-system-queryexception/</a>). Of course your method and a try-catch are simply the same thing implemented differently:) Good article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Hemmeter</title>
		<link>http://theEnforcer.net/2009/09/list-has-no-rows-for-assignment-to-sobject/comment-page-1/#comment-71032</link>
		<dc:creator>Scott Hemmeter</dc:creator>
		<pubDate>Mon, 14 Sep 2009 15:29:15 +0000</pubDate>
		<guid isPermaLink="false">http://theEnforcer.net/?p=122#comment-71032</guid>
		<description>An approach I often use is to always use a FOR loop for the query. It will only go into the loop if something is returned. Only downside is that you need to declare variables outside the loop you want to use them outside the loop. If you declare them in th loop, the system can&#039;t see them after the loop is complete.</description>
		<content:encoded><![CDATA[<p>An approach I often use is to always use a FOR loop for the query. It will only go into the loop if something is returned. Only downside is that you need to declare variables outside the loop you want to use them outside the loop. If you declare them in th loop, the system can&#8217;t see them after the loop is complete.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Enforcer</title>
		<link>http://theEnforcer.net/2009/09/list-has-no-rows-for-assignment-to-sobject/comment-page-1/#comment-71031</link>
		<dc:creator>The Enforcer</dc:creator>
		<pubDate>Sun, 13 Sep 2009 02:38:54 +0000</pubDate>
		<guid isPermaLink="false">http://theEnforcer.net/?p=122#comment-71031</guid>
		<description>Oops! Thanks for finding the error, Tom!

I was checking &lt;code&gt;players != null&lt;/code&gt;, but should be checking &lt;code&gt;players.size() &gt; 0&lt;/code&gt;. Now corrected. &lt;blush&gt;</description>
		<content:encoded><![CDATA[<p>Oops! Thanks for finding the error, Tom!</p>
<p>I was checking <code>players != null</code>, but should be checking <code>players.size() > 0</code>. Now corrected. &lt;blush&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Davies</title>
		<link>http://theEnforcer.net/2009/09/list-has-no-rows-for-assignment-to-sobject/comment-page-1/#comment-71030</link>
		<dc:creator>Tom Davies</dc:creator>
		<pubDate>Sat, 12 Sep 2009 23:45:54 +0000</pubDate>
		<guid isPermaLink="false">http://theEnforcer.net/?p=122#comment-71030</guid>
		<description>IMHO it is nocer to get an immediate runtime exception than a null reference which might blow up later.

Is the last example really correct? That is, does SELECT return null for no rows rather than an empty list?</description>
		<content:encoded><![CDATA[<p>IMHO it is nocer to get an immediate runtime exception than a null reference which might blow up later.</p>
<p>Is the last example really correct? That is, does SELECT return null for no rows rather than an empty list?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

