<?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>The Enforcer.net &#187; formulas</title>
	<atom:link href="http://theEnforcer.net/category/formulas/feed/" rel="self" type="application/rss+xml" />
	<link>http://theEnforcer.net</link>
	<description>a force.com blog</description>
	<lastBuildDate>Thu, 19 Aug 2010 23:03:36 +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>Making Owner available in Formulas</title>
		<link>http://theEnforcer.net/2010/06/making-owner-available-in-formulas/</link>
		<comments>http://theEnforcer.net/2010/06/making-owner-available-in-formulas/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 07:37:26 +0000</pubDate>
		<dc:creator>The Enforcer</dc:creator>
				<category><![CDATA[Apex]]></category>
		<category><![CDATA[Data Loader]]></category>
		<category><![CDATA[Force.com IDE]]></category>
		<category><![CDATA[formulas]]></category>

		<guid isPermaLink="false">http://theEnforcer.net/?p=228</guid>
		<description><![CDATA[I was configuring DataLoader to export a list of Opportunities, and I went to select the &#8220;Owner Name&#8221;. However, only OwnerID is available on an Opportunity. &#8220;No problem!&#8221; I think to myself, as I go and create a Custom Field with a formula equal to Owner.Alias. &#8220;What?&#8221; I say in surprise. &#8220;It won&#8217;t let me [...]]]></description>
			<content:encoded><![CDATA[<p>I was configuring DataLoader to export a list of Opportunities, and I went to select the &#8220;Owner Name&#8221;. However, only <code>OwnerID</code> is available on an Opportunity.</p>
<p>&#8220;No problem!&#8221; I think to myself, as I go and create a Custom Field with a formula equal to <code>Owner.Alias</code>.</p>
<p>&#8220;What?&#8221; I say in surprise. &#8220;It won&#8217;t let me access a field on the Owner object!&#8221;</p>
<p><img class="aligncenter size-full wp-image-229" title="NoLink" src="http://theEnforcer.net/wp-content/uploads/2010/06/NoLink.gif" alt="NoLink" width="302" height="136" /></p>
<p>Mmm. This is strange. Then a Google Search reveals an 18-month old Ideas request to <a href="http://sites.force.com/ideaexchange/apex/ideaview?id=08730000000BrqaAAC" target="_blank">Make &#8220;Owner Id&#8221; Look up fields available for formulas</a>.</p>
<p>Oh dear.</p>
<p>Well, that&#8217;s a shame, but it&#8217;s easily solved! I created:</p>
<ul>
<li>A field called <code>Owner_Link__c</code> of type <code>Lookup(User)</code></li>
<li>A Trigger to copy<code> OwnerId</code> to <code>Owner_Link__c</code> when the Owner is changed</li>
<li>A test for the Trigger</li>
</ul>
<p><strong>Trigger:</strong></p>
<pre class="brush: java;">
trigger Update_OwnerLink_on_Owner_Update on Opportunity (before update, before insert) {

  // When 'Owner' field is changed, update 'OwnerLink' too

	// Loop through the incoming records
	for (Opportunity o : Trigger.new) {

		// Has Owner chagned?
		if (o.OwnerID != o.Owner_Link__c) {
			o.Owner_Link__c = o.OwnerId;
		}
	}
}
</pre>
<p><strong>Test:</strong></p>
<pre class="brush: java;">
public with sharing class TriggerTest_OwnerLink {

	static TestMethod void testOwnerLink() {

		// Grab two Users
		User[] users = [select Id from User limit 2];
		User u1 = users[0];
		User u2 = users[1];

		// Create an Opportunity
		System.debug('Creating Opportunity');
		Opportunity o1 = new Opportunity(CloseDate = Date.newInstance(2008, 01, 01), Name = 'Test Opportunity', StageName = 'New', OwnerId = u1.Id);
		insert o1;

		// Test: Owner_Link should be set to user 1
		Opportunity o2 = [select id, OwnerId, Owner_Link__c from Opportunity where Id = :o1.Id];
		System.assertEquals(u1.Id, o2.OwnerId);
		System.assertEquals(u1.Id, o2.Owner_Link__c);

		// Modify Owner
		o2.OwnerId = u2.Id;
		update o2;

		// Test: Owner_Link should be set to user 2
		Opportunity o3 = [select id, OwnerId, Owner_Link__c from Opportunity where Id = :o2.Id];
		System.assertEquals(u2.Id, o3.OwnerId);
		System.assertEquals(u2.Id, o3.Owner_Link__c);
	}
}
</pre>
<p>This then gave me a new Owner object on my Opportunity on which I could create Formulas:</p>
<p><img src="http://theEnforcer.net/wp-content/uploads/2010/06/Result.png" alt="Result" title="Result" width="626" height="139" class="aligncenter size-full wp-image-234" /></p>
<p>I could also use it in the DataLoader by referring to <code>Owner_Link__r.Alias</code>.</p>
<p>Hooray!</p>
<p>Easy to solve, but it&#8217;s a shame it was necessary.</p>
<h3>The Bottom Line</h3>
<ul class="nomargin">
<li>Formulas can&#8217;t access <code>Opportunity.Owner</code> fields</li>
<li>Create a &#8216;shadow&#8217; field to hold Owner and populate it via a Trigger</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://theEnforcer.net/2010/06/making-owner-available-in-formulas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use formulas to make small links</title>
		<link>http://theEnforcer.net/2008/07/use-formulas-to-make-small-links/</link>
		<comments>http://theEnforcer.net/2008/07/use-formulas-to-make-small-links/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 06:13:45 +0000</pubDate>
		<dc:creator>The Enforcer</dc:creator>
				<category><![CDATA[formulas]]></category>

		<guid isPermaLink="false">http://theenforcer.net/?p=36</guid>
		<description><![CDATA[I wanted to add a Link to a related list, which would take the user to an external system. Problem was, if I used a URL field, Salesforce.com wanted to show the entire URL within the Related List. This was so long that it drowned-out the other information. With a bit of experimenting, I managed [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to add a Link to a related list, which would take the user to an external system.</p>
<p>Problem was, if I used a URL field, Salesforce.com wanted to show the entire URL within the Related List. This was so long that it drowned-out the other information.</p>
<p>With a bit of experimenting, I managed to create a Formula that produced a very small link.</p>
<p style="text-align: center;"><img class="aligncenter" src="http://theenforcer.net/wp-content/uploads/2008/07/viewlink.png" alt="" width="453" height="154" /></p>
<p>How&#8217;d I do it? By using the <code>HYPERLINK</code> function.</p>
<pre>HYPERLINK("http://www.website.com/info/ViewDetails.jspa?orderId=" &amp; Activity_ID__c, "View", "_blank")</pre>
<p>This lets me build a URL based upon some partial information in a record (eg ID number) rather than having to store the entire URL within the record.</p>
<h3>The Bottom Line</h3>
<ul class="nomargin">
<li>Use <code>HYPERLINK</code> to make a URL instead of creating a field of type <code>URL</code></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://theEnforcer.net/2008/07/use-formulas-to-make-small-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
