<?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>Jeff Douglas - Technology, Coding and Bears... OH MY! &#187; Cloud Computing</title>
	<atom:link href="http://blog.jeffdouglas.com/category/cloud-computing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jeffdouglas.com</link>
	<description>Get your head out of your #@! and into the clouds!</description>
	<lastBuildDate>Thu, 29 Jul 2010 19:04:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Force.com Explorer (beta) for Adobe Air Available</title>
		<link>http://blog.jeffdouglas.com/2010/07/29/force-explorer-for-adobe-air-available/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=force-explorer-for-adobe-air-available</link>
		<comments>http://blog.jeffdouglas.com/2010/07/29/force-explorer-for-adobe-air-available/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 19:04:52 +0000</pubDate>
		<dc:creator>Jeff Douglas</dc:creator>
				<category><![CDATA[Salesforce]]></category>

		<guid isPermaLink="false">http://blog.jeffdouglas.com/?p=2990</guid>
		<description><![CDATA[A copy of the new Force.com Developer News arrived in my inbox this morning with some interesting news. An Adobe Air (beta) of the Force.com Explorer has been released for people to begin playing with. If you missed the newsletter, you can catch Jon Mountjoy&apos;s blog post with the announcement. Jon writes more eloquently than [...]]]></description>
			<content:encoded><![CDATA[<p>A copy of the new Force.com Developer News arrived in my inbox this morning with some interesting news. An Adobe Air (beta) of the Force.com Explorer has been released for people to begin playing with. If you missed the newsletter, you can catch Jon Mountjoy&apos;s <a href="http://blog.sforce.com/sforce/2010/07/forcecom-explorer-beta-is-out.html">blog post</a> with the announcement. Jon writes more eloquently than me due to his enchanting accent. You should give the app a whirl as it&#8217;s off to a good start. You can <a href="http://wiki.developerforce.com/index.php/ForceExplorer" target="_blank">download it here</a>.</p>
<p><a href="http://blog.jeffdouglas.com/2010/07/29/force-explorer-for-adobe-air-available/force-explorer1/" rel="attachment wp-att-2992"><img src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/force-explorer1.png" alt="" title="force-explorer1" width="480" height="370" class="alignnone size-full wp-image-2992" /></a></p>
<p>I was quite excited to see how the Adobe Flash Builder for Force.com was coming along since I <a href="http://blog.jeffdouglas.com/2010/02/01/adobe-air-applications-with-salesforce/">developed a small app</a> with the toolkit last January. I took a peek at the docs and they&#8217;ve made some really nice progress. However, the main reason I immediately downloaded the Force.com Explorer was to test out the functionality in hopes of a better tool. If you are a Mac user than you are blessed with the options of running Simon Fell&#8217;s <a href="http://www.pocketsoap.com/osx/soqlx/">SoqlXplorer</a> in addition to the Force.com IDE for Eclipse. Neither one is quite the perfect tool. SoqlXplorer doesn&#8217;t let you drill into objects to build complex relationship queries like Eclipse but the Eclipse IDE doesn&#8217;t allow you to copy the resulting data from queries into your clipboard. I typically live in the SoqlXplorer all day. (Side note: not being able to copy results in the Eclipse IDE is frustrating but Job Plax, the Force.com IDE PM, told me that this feature just missed the last release so hopefully it will be in a future release.)</p>
<p>The Force.com Explorer is a breeze to install if you already have Adobe Air and you can be up and running within seconds. It has a nice clean UI which looks a lot like the .NET Apex Explorer. It has most of the functionality that you find in the other SOQL query tool plus some:</p>
<ol>
<li>Filter objects by name</li>
<li>Drill down into objects and relationships to create complex queries. Very similar in functionality to the Eclipse IDE</li>
<li>Return results with child object that you can click on to drill into</li>
<li>Copy the text from cells in the query results</li>
<li>View metadata about the objects</li>
<li>Query, query all and batch size options</li>
<li>Right click on an object to view it of its metadata and save it as a PDF</li>
<li>It remembers the fields you selected in previous objects to easily rebuild SOQL queries</li>
</ol>
<p>Some issues that I found right away (BTW&#8230; email any issues or requests to <a href="mailto:developerforce@salesforce.com">developerforce@salesforce.com</a>):</p>
<ol>
<li>I was not able to log into any sandbox orgs</li>
<li>I had a problem printing the object report but could download it as a PDF with no problems.</li>
<li>It crashed a couple of times while trying to create complex queries</li>
<li>It was not able to construct queries with parent-to-child relationships and if I did manually enter them the results came back null.</li>
</ol>
<p><b>View Child Records Inline</b>
<p><img src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/force-explorer4.png" width="480" height="370" alt="force-explorer4.png" /></p>
<p><b>View Metadata about an Object</b></p>
<p><a href="http://blog.jeffdouglas.com/2010/07/29/force-explorer-for-adobe-air-available/force-explorer3/" rel="attachment wp-att-2993"><img src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/force-explorer3.png" alt="" title="force-explorer3" width="480" height="370" class="alignnone size-full wp-image-2993" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeffdouglas.com/2010/07/29/force-explorer-for-adobe-air-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the Salesforce.com OAuth Playground</title>
		<link>http://blog.jeffdouglas.com/2010/07/28/using-the-salesforce-oauth-playground/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-the-salesforce-oauth-playground</link>
		<comments>http://blog.jeffdouglas.com/2010/07/28/using-the-salesforce-oauth-playground/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 12:39:25 +0000</pubDate>
		<dc:creator>Jeff Douglas</dc:creator>
				<category><![CDATA[Apex]]></category>
		<category><![CDATA[Salesforce]]></category>

		<guid isPermaLink="false">http://blog.jeffdouglas.com/?p=2968</guid>
		<description><![CDATA[﻿My article on developer.force.com, Using OAuth to Authorize External Applications, shows how to develop external Java applications that use OAuth to access your Saleforce.com data. But what if you want to do the opposite? What if you need to write an application on the Force.com platform that uses your data from Google, Twitter, LinkedIn or [...]]]></description>
			<content:encoded><![CDATA[<p>﻿My article on developer.force.com, <a href="http://wiki.developerforce.com/index.php/Using_OAuth_to_Authorize_External_Applications">Using OAuth to Authorize External Applications</a>, shows how to develop external Java applications that use OAuth to access your Saleforce.com data. But what if you want to do the opposite? What if you need to write an application on the Force.com platform that uses your data from Google, Twitter, LinkedIn or TripIt using OAuth? Luckily <a href="http://twitter.com/jesperfj">Jesper Jorgenson</a> at Salesforce.com posted an open source project called <a href="http://code.google.com/p/sfdc-oauth-playground/">sfdc-oauth-playground</a> which is a generic consumer implementation of OAuth as a Force.com App.</p>
<p>The main purpose of this beta project is to show you how to write OAuth signed requests in Apex. There is a managed packaged you can install into your org but if you really want to dig into the guts of OAuth (and who doesn&#8217;t??) you&#8217;ll need to download and install the source code from the project. The managed package doesn&#8217;t afford you to opportunity to modify code or view granular debug statements.</p>
<p>Jesper doesn&#8217;t provide much documentation for the project so I&#8217;ve put together a short video showing how to get started using Google Accounts and Blogger. Unfortunately different providers implement OAuth to their own liking so you sometimes have to make modifications to the requests being sent over the wire. I ran into a number of issues so hopefully this will assist you in getting up and running with OAuth.</p>
<p><span class="youtube">
<object width="480" height="295">
<param name="movie" value="http://www.youtube.com/v/sXJxG6zWSZA&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0?rel=1&amp;hd=1&#038;hd=1&#038;w=600]" />
<param name="allowFullScreen" value="true" />
<embed wmode="transparent" src="http://www.youtube.com/v/sXJxG6zWSZA&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0?rel=1&amp;hd=1&#038;hd=1&#038;w=600]" type="application/x-shockwave-flash" allowfullscreen="true" width="480" height="295"></embed>
<param name="wmode" value="transparent" />
</object>
</span><p><a href="http://www.youtube.com/watch?v=sXJxG6zWSZA&fmt=18">www.youtube.com/watch?v=sXJxG6zWSZA</a></p></p>
<p> </p>
<p>﻿In case you don&#8217;t have time for the video, here are a couple of screenshots outlining the process using the OAuth Consumer Playground application from the managed package.</p>
<p><strong>﻿Create a new OAuth Service (e.g., Blogger) with various URLs for accessing services</strong></p>
<p><a href="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-unauthorized1_large.png" rel="lightbox[2968]"><img title="oauth-service-unauthorized.png" src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-unauthorized1.png" border="0" alt="oauth-service-unauthorized.png" width="400" height="308" /></a></p>
<p> </p>
<p>﻿<strong>Authorize Salesforce access to Blogger</strong></p>
<p><a href="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-preauth1_large.png" rel="lightbox[2968]"><img title="oauth-service-preauth.png" src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-preauth1.png" border="0" alt="oauth-service-preauth.png" width="400" height="266" /></a></p>
<p> </p>
<p><strong>﻿Grant access to Blogger</strong></p>
<p><a href="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-blogger_large.png" rel="lightbox[2968]"><img title="oauth-service-blogger.png" src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-blogger.png" border="0" alt="oauth-service-blogger.png" width="400" height="266" /></a></p>
<p> </p>
<p><strong>﻿Authorization confirmation</strong></p>
<p><a href="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-auth_large.png" rel="lightbox[2968]"><img title="oauth-service-auth.png" src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-auth.png" border="0" alt="oauth-service-auth.png" width="400" height="266" /></a></p>
<p> </p>
<p>﻿<strong>OAuth Service access tokens</strong></p>
<p><a href=""http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-authorized_large.png"><img title="oauth-service-authorized.png" src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-authorized.png" border="0" alt="oauth-service-authorized.png" width="400" height="308" /></a></p>
<p> </p>
<p><strong>﻿Testing the service</strong></p>
<p><a href="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-test_large.png" rel="lightbox[2968]"><img title="oauth-service-test.png" src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/oauth-service-test.png" border="0" alt="oauth-service-test.png" width="400" height="333" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeffdouglas.com/2010/07/28/using-the-salesforce-oauth-playground/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using OAuth to Authorize External Applications</title>
		<link>http://blog.jeffdouglas.com/2010/07/23/using-oauth-to-authorize-external-applications-2/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-oauth-to-authorize-external-applications-2</link>
		<comments>http://blog.jeffdouglas.com/2010/07/23/using-oauth-to-authorize-external-applications-2/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 10:09:36 +0000</pubDate>
		<dc:creator>Jeff Douglas</dc:creator>
				<category><![CDATA[Salesforce]]></category>

		<guid isPermaLink="false">http://blog.jeffdouglas.com/?p=2914</guid>
		<description><![CDATA[My article on OAuth went up yesterday on developer.force.com (thanks Jon!). It seems like OAuth is gaining adoption so I hope the article comes in handy for people developing applications for Salesforce.com. I&#8217;m currently working on another article for the Force.com Web Services Connector (WSC). &#8220;Force.com lets you build external web applications that access data [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both"><a href="http://wiki.developerforce.com/index.php/Using_OAuth_to_Authorize_External_Applications" target="_blank">My article on OAuth</a> went up yesterday on developer.force.com (thanks Jon!). It seems like OAuth is gaining adoption so I hope the article comes in handy for people developing applications for Salesforce.com. I&#8217;m currently working on another article for the F<a href="http://code.google.com/p/sfdc-wsc/" target="_blank">orce.com Web Services Connector</a> (WSC). </p>
<p style="clear: both"><a href="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/sfdc-oauth-demo1.png" class="image-link" rel="lightbox[2914]"><img class="linked-to-original" src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/sfdc-oauth-demo1-thumb1.png" height="55" align="left" width="267" style=" display: inline; float: left; margin: 0 10px 10px 0;" /></a><br style="clear: both" />&#8220;Force.com lets you build external web applications that access data on the Force.com platform using the Oauth 1.0a protocol. OAuth is an open protocol that allows a website to access resources of another website without having to expose a user&#8217;s credentials. Instead of supplying a username and password, OAuth allows users to hand out security tokens to specific sites for access to specific resources for a defined duration.</p>
<p style="clear: both">In this article we&#8217;ll explain what OAuth is and why you should use it. We&#8217;ll also configure a Remote Access Application in Force.com, and develop an application on Google App Engine that uses a Remote Access Application to authorize access to Force.com to display account and contact records. Finally, we&#8217;ll look at some tips, tricks, available libraries and best practices to get you up and running in no time.&#8221;</p>
<p style="clear: both"><a href="http://wiki.developerforce.com/index.php/Using_OAuth_to_Authorize_External_Applications" target="_blank">Read the entires article at developer.force.com</a></p>
<p style="clear: both">All of the code for the application is available at the Google Code project: <a href="http://code.google.com/p/sfdc-oauth-demo/" target="_blank">sfdc-oauth-demo</a></p>
<p><br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeffdouglas.com/2010/07/23/using-oauth-to-authorize-external-applications-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Email a Document with Salesforce.com</title>
		<link>http://blog.jeffdouglas.com/2010/07/22/create-and-email-a-document-with-salesforce-com/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=create-and-email-a-document-with-salesforce-com</link>
		<comments>http://blog.jeffdouglas.com/2010/07/22/create-and-email-a-document-with-salesforce-com/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 10:39:28 +0000</pubDate>
		<dc:creator>Jeff Douglas</dc:creator>
				<category><![CDATA[Apex]]></category>
		<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Visualforce]]></category>

		<guid isPermaLink="false">http://blog.jeffdouglas.com/?p=2895</guid>
		<description><![CDATA[After my last post, Create and Email a PDF with Salesforce.com, I received a few comments whether it was possible to do the same with Document stored in Salesforce.com. Could you choose a Document and then send it via email as an attachment? The short answer is yes! However, I tried to do it from [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both">After my last post, <a href="http://blog.jeffdouglas.com/2010/07/16/create-and-email-a-pdf-with-salesforce-com/" target="_blank">Create and Email a PDF with Salesforce.com</a>, I received a few comments whether it was possible to do the same with Document stored in Salesforce.com. Could you choose a Document and then send it via email as an attachment? The short answer is yes! However, I tried to do it from a Force.com Sites page but was not able to get it to work. The document is not marked for internal use and it is marked as an externally available image. I also made sure that the public settings for my Site included read access to documents but still the query for the document returns no results. No time to look at it in depth right now so if anyone has an idea, please send it my way.</p>
<p style="clear: both"><a href="http://blog.jeffdouglas.com/2010/07/22/create-and-email-a-document-with-salesforce-com/email-doc/" rel="attachment wp-att-2896"><img src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/email-doc.png" alt="" title="email-doc" width="500" class="alignnone size-full wp-image-2896" /></a></p>
<p style="clear: both"><strong>DocumentEmailer Visualforce Page</strong></p>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>page controller<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;DocumentEmailController&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>sectionHeader title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Document Example&quot;</span> subtitle<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Email a Document&quot;</span> 
    description<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Example of how to email a Document.&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>form <span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageMessages <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlock title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Document Input&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockButtons <span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>commandButton action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!sendDoc}&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Send Document&quot;</span><span style="color: #339933;">/&gt;</span>
      <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockButtons<span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockSection <span style="color: #339933;">&gt;</span>
&nbsp;
        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem <span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>outputLabel value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Email to send to&quot;</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #339933;">/&gt;</span>
          <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>inputText value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!email}&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem<span style="color: #339933;">&gt;</span>
&nbsp;
        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem <span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>outputLabel value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Document&quot;</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;document&quot;</span><span style="color: #339933;">/&gt;</span>
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>selectList value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!documentId}&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;document&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">&gt;</span>
                 <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>selectOptions value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!documents}&quot;</span><span style="color: #339933;">/&gt;</span>
            <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>selectList<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem<span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockSection<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlock<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>page<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</p>
<p style="clear: both"><strong>DocumentEmailController</strong></p>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> with sharing <span style="color: #000000; font-weight: bold;">class</span> DocumentEmailController <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> ID documentId <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> <span style="color: #003399;">String</span> email <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> List<span style="color: #339933;">&lt;</span>SelectOption<span style="color: #339933;">&gt;</span> documents <span style="color: #009900;">&#123;</span>
    get <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>documents <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        documents <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> List<span style="color: #339933;">&lt;</span>SelectOption<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        documents.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SelectOption<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'01570000001NZDn'</span>,<span style="color: #0000ff;">'Cup of Coffee? - DOC'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        documents.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SelectOption<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'01570000001NZDi'</span>,<span style="color: #0000ff;">'Workflow Cheatsheet -  PDF'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">return</span> documents<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    set<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> PageReference sendDoc<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #003399;">Document</span> doc <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>select id, name, body, contenttype, developername, type 
      from <span style="color: #003399;">Document</span> where id <span style="color: #339933;">=</span> <span style="color: #339933;">:</span>documentId<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    Messaging.<span style="color: #006633;">EmailFileAttachment</span> attach <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Messaging.<span style="color: #006633;">EmailFileAttachment</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    attach.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">contentType</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    attach.<span style="color: #006633;">setFileName</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">developerName</span><span style="color: #339933;">+</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">+</span>doc.<span style="color: #006633;">type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    attach.<span style="color: #006633;">setInline</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    attach.<span style="color: #006633;">Body</span> <span style="color: #339933;">=</span> doc.<span style="color: #006633;">Body</span><span style="color: #339933;">;</span>
&nbsp;
    Messaging.<span style="color: #006633;">SingleEmailMessage</span> mail <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Messaging.<span style="color: #006633;">SingleEmailMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mail.<span style="color: #006633;">setUseSignature</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mail.<span style="color: #006633;">setToAddresses</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> email <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mail.<span style="color: #006633;">setSubject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Document Email Demo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mail.<span style="color: #006633;">setHtmlBody</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Here is the email you requested: '</span><span style="color: #339933;">+</span>doc.<span style="color: #006633;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mail.<span style="color: #006633;">setFileAttachments</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Messaging.<span style="color: #006633;">EmailFileAttachment</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> attach <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
    <span style="color: #666666; font-style: italic;">// Send the email</span>
    Messaging.<span style="color: #006633;">sendEmail</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Messaging.<span style="color: #006633;">SingleEmailMessage</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> mail <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    ApexPages.<span style="color: #006633;">addMessage</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ApexPages.<span style="color: #006633;">Message</span><span style="color: #009900;">&#40;</span>ApexPages.<span style="color: #006633;">Severity</span>.<span style="color: #006633;">INFO</span>, <span style="color: #0000ff;">'Email with Document sent to '</span><span style="color: #339933;">+</span>email<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</p>
<p style="clear: both"><strong>Test Class</strong></p>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">@isTest
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> Test_DocumentEmailer <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Document</span> document<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    document <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Document</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    document.<span style="color: #006633;">Body</span> <span style="color: #339933;">=</span> <span style="color: #003399;">Blob</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Some Text'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    document.<span style="color: #006633;">ContentType</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'application/pdf'</span><span style="color: #339933;">;</span>
    document.<span style="color: #006633;">DeveloperName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'my_document'</span><span style="color: #339933;">;</span>
    document.<span style="color: #006633;">IsPublic</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    document.<span style="color: #003399;">Name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'My Document'</span><span style="color: #339933;">;</span>
    document.<span style="color: #006633;">FolderId</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>select id from folder where name <span style="color: #339933;">=</span> <span style="color: #0000ff;">'My Test Docs'</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">id</span><span style="color: #339933;">;</span>
    insert document<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> testMethod <span style="color: #000066; font-weight: bold;">void</span> testDocumentEmailer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    PageReference pref <span style="color: #339933;">=</span> Page.<span style="color: #006633;">DocumentEmailer</span><span style="color: #339933;">;</span>        
    DocumentEmailController con <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DocumentEmailController<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
&nbsp;
    Test.<span style="color: #006633;">startTest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003399;">System</span>.<span style="color: #006633;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>,con.<span style="color: #006633;">documents</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// populate the field with values</span>
    con.<span style="color: #006633;">documentId</span> <span style="color: #339933;">=</span> document.<span style="color: #006633;">id</span><span style="color: #339933;">;</span>
    con.<span style="color: #006633;">email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test@noemail.com'</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// submit the request</span>
    pref <span style="color: #339933;">=</span> con.<span style="color: #006633;">sendDoc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    Test.<span style="color: #006633;">stopTest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</p>
<p><br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeffdouglas.com/2010/07/22/create-and-email-a-document-with-salesforce-com/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create and Email a PDF with Salesforce.com</title>
		<link>http://blog.jeffdouglas.com/2010/07/16/create-and-email-a-pdf-with-salesforce-com/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=create-and-email-a-pdf-with-salesforce-com</link>
		<comments>http://blog.jeffdouglas.com/2010/07/16/create-and-email-a-pdf-with-salesforce-com/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 12:03:15 +0000</pubDate>
		<dc:creator>Jeff Douglas</dc:creator>
				<category><![CDATA[Apex]]></category>
		<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Visualforce]]></category>

		<guid isPermaLink="false">http://blog.jeffdouglas.com/?p=2883</guid>
		<description><![CDATA[This is a continuation of my post a couple of days ago, Attach a PDF to a Record in Salesforce, and shows how to dynamically generate a PDF and attach it to an email. The code is fairly similar and has the same issue with testing the PageReference getContent() method. You can run this demo [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both">This is a continuation of my post a couple of days ago, <a href="http://blog.jeffdouglas.com/2010/07/14/attach-a-pdf-to-a-record-in-salesforce/" target="_blank">Attach a PDF to a Record in Salesforce</a>, and shows how to dynamically generate a PDF and attach it to an email. The code is fairly similar and has the same issue with testing the PageReference getContent() method.</p>
<p style="clear: both">
<h3 style="text-decoration:underline; clear: both"><a href="https://jeffdouglas-developer-edition.na5.force.com/examples/PdfEmailer" target="_blank">You can run this demo at my developer site.</a></h3>
</p>
<p style="clear: both"><a href="https://jeffdouglas-developer-edition.na5.force.com/examples/PdfEmailer"><img src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/email-pdf.png" alt="" title="email-pdf" width="500" height="237" class="alignnone size-full wp-image-2889" /></a>
<p><strong>PdfEmailer Visualforce Page</strong></p>
<p style="clear: both">The Visualforce page simply allows the user to enter their email address and select a sample Account from the picklist. This is Account that is passed to the PdfGeneratorTemplate Visualforce page to generate the PDF.</p>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>page controller<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;PdfEmailController&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>sectionHeader title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;PDF Example&quot;</span> subtitle<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Email a PDF&quot;</span> 
    description<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Example of how to email a dynamically generated PDF.&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>form <span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageMessages <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlock title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;PDF Input&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockButtons <span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>commandButton action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!sendPdf}&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Send PDF&quot;</span><span style="color: #339933;">/&gt;</span>
      <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockButtons<span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockSection <span style="color: #339933;">&gt;</span>
&nbsp;
        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem <span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>outputLabel value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Email to send to&quot;</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #339933;">/&gt;</span>
          <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>inputText value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!email}&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem<span style="color: #339933;">&gt;</span>
&nbsp;
        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem <span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>outputLabel value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Account&quot;</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;account&quot;</span><span style="color: #339933;">/&gt;</span>
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>selectList value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!accountId}&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;account&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">&gt;</span>
                 <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>selectOptions value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!accounts}&quot;</span><span style="color: #339933;">/&gt;</span>
            <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>selectList<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem<span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockSection<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlock<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>page<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</p>
<p style="clear: both"><strong>PdfEmailerController</strong></p>
<p style="clear: both">The Controller passes the Account ID that the user entered as a parameter for the Visualforce page being generated. It let creates the attachment from the PDF content. The Body of the attachment uses the Blob returned from the PageReference’s getContent method. You could also use the getContentAsPDF method which always returns the page as a PDF, regardless of the <apex:page> component’s renderAs attribute. However, this method always seems to throw an error in the test class. See the <a href="http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_pagereference.htm" target="_blank">PageReference documentation</a> for more info. The method then constructs the SimpleEmailMessage object and then sends it on its way to the recipient&#8217;s inbox.</p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> with sharing <span style="color: #000000; font-weight: bold;">class</span> PdfEmailController <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> ID accountId <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> <span style="color: #003399;">String</span> email <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> List<span style="color: #339933;">&lt;</span>SelectOption<span style="color: #339933;">&gt;</span> accounts <span style="color: #009900;">&#123;</span>
    get <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>accounts <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        accounts <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> List<span style="color: #339933;">&lt;</span>SelectOption<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        accounts.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SelectOption<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'0017000000LgRMb'</span>,<span style="color: #0000ff;">'United Oil &amp; Gas Corp.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        accounts.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SelectOption<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'0017000000LgRMV'</span>,<span style="color: #0000ff;">'Burlington Textiles Corp of America'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">return</span> accounts<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    set<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> PageReference sendPdf<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    PageReference pdf <span style="color: #339933;">=</span> Page.<span style="color: #006633;">PdfGeneratorTemplate</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// add parent id to the parameters for standardcontroller</span>
    pdf.<span style="color: #006633;">getParameters</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span>,accountId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// the contents of the attachment from the pdf</span>
    <span style="color: #003399;">Blob</span> body<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// returns the output of the page as a PDF</span>
      body <span style="color: #339933;">=</span> pdf.<span style="color: #006633;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// need to pass unit test -- current bug  </span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>VisualforceException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      body <span style="color: #339933;">=</span> <span style="color: #003399;">Blob</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Some Text'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    Messaging.<span style="color: #006633;">EmailFileAttachment</span> attach <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Messaging.<span style="color: #006633;">EmailFileAttachment</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    attach.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'application/pdf'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    attach.<span style="color: #006633;">setFileName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'testPdf.pdf'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    attach.<span style="color: #006633;">setInline</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    attach.<span style="color: #006633;">Body</span> <span style="color: #339933;">=</span> body<span style="color: #339933;">;</span>
&nbsp;
    Messaging.<span style="color: #006633;">SingleEmailMessage</span> mail <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Messaging.<span style="color: #006633;">SingleEmailMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mail.<span style="color: #006633;">setUseSignature</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mail.<span style="color: #006633;">setToAddresses</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> email <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mail.<span style="color: #006633;">setSubject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PDF Email Demo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mail.<span style="color: #006633;">setHtmlBody</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Here is the email you requested! Check the attachment!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mail.<span style="color: #006633;">setFileAttachments</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Messaging.<span style="color: #006633;">EmailFileAttachment</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> attach <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
    <span style="color: #666666; font-style: italic;">// Send the email</span>
    Messaging.<span style="color: #006633;">sendEmail</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Messaging.<span style="color: #006633;">SingleEmailMessage</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> mail <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    ApexPages.<span style="color: #006633;">addMessage</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ApexPages.<span style="color: #006633;">Message</span><span style="color: #009900;">&#40;</span>ApexPages.<span style="color: #006633;">Severity</span>.<span style="color: #006633;">INFO</span>, <span style="color: #0000ff;">'Email with PDF sent to '</span><span style="color: #339933;">+</span>email<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</p>
<p><strong>PdfGeneratorTemplate Visualforce Page</strong>
<p>This is the Visualforce page that is generated in the Controller. It simply uses the StandardController and displays the Account name for the ID passed to it.
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>page standardController<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Account&quot;</span> renderAs<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pdf&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span>Congratulations<span style="color: #339933;">!!&lt;/</span>h1<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>You created a PDF <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#123;</span><span style="color: #339933;">!</span>account.<span style="color: #006633;">name</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>page<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</p>
<p><strong>Test Class</strong>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">@isTest
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> Test_PdfEmailController <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> Account account<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    account <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Account<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    account.<span style="color: #003399;">Name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Test Account'</span><span style="color: #339933;">;</span>
    insert account<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> testMethod <span style="color: #000066; font-weight: bold;">void</span> testPdfEmailer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    PageReference pref <span style="color: #339933;">=</span> Page.<span style="color: #006633;">PdfEmailer</span><span style="color: #339933;">;</span>
    pref.<span style="color: #006633;">getParameters</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span>,account.<span style="color: #006633;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Test.<span style="color: #006633;">setCurrentPage</span><span style="color: #009900;">&#40;</span>pref<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    PdfEmailController con <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PdfEmailController<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
&nbsp;
    Test.<span style="color: #006633;">startTest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003399;">System</span>.<span style="color: #006633;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>,con.<span style="color: #006633;">accounts</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// populate the field with values</span>
    con.<span style="color: #006633;">accountId</span> <span style="color: #339933;">=</span> account.<span style="color: #006633;">id</span><span style="color: #339933;">;</span>
    con.<span style="color: #006633;">email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test@noemail.com'</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// submit the record</span>
    pref <span style="color: #339933;">=</span> con.<span style="color: #006633;">sendPdf</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    Test.<span style="color: #006633;">stopTest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeffdouglas.com/2010/07/16/create-and-email-a-pdf-with-salesforce-com/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Attach a PDF to a Record in Salesforce</title>
		<link>http://blog.jeffdouglas.com/2010/07/14/attach-a-pdf-to-a-record-in-salesforce/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=attach-a-pdf-to-a-record-in-salesforce</link>
		<comments>http://blog.jeffdouglas.com/2010/07/14/attach-a-pdf-to-a-record-in-salesforce/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 13:57:33 +0000</pubDate>
		<dc:creator>Jeff Douglas</dc:creator>
				<category><![CDATA[Apex]]></category>
		<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Visualforce]]></category>

		<guid isPermaLink="false">http://blog.jeffdouglas.com/?p=2854</guid>
		<description><![CDATA[Salesforce.com makes it extremely easy to generate PDF documents on the fly by simply using the renderAs=&#8221;pdf&#8221; attribute for the &#60;apex:page&#62; component. It&#8217;s also a snap to attach these PDFs to records as Attachments. Below is a small Visualforce page and Controller that generates a PDF and saves it to an Account. Note: there is [...]]]></description>
			<content:encoded><![CDATA[<p>Salesforce.com makes it extremely easy to generate PDF documents on the fly by simply using the renderAs=&#8221;pdf&#8221; attribute for the &lt;apex:page&gt; component. It&#8217;s also a snap to attach these PDFs to records as Attachments. Below is a small Visualforce page and Controller that generates a PDF and saves it to an Account.</p>
<p><strong>Note:</strong> there is a small issue when it comes to testing the Controller. Salesforce currently throws an error (Salesforce.com Error &#8220;Unable to retrieve object&#8221;) when getContent or getContentAsPDF is called from a test method. There&#8217;s an <a href="http://sites.force.com/ideaexchange/ideaView?c=09a30000000D9xt&#038;id=08730000000HzknAAC" target="_blank">Idea to make this work</a> properly. I encourage everyone to vote for this.</p>
<p><a href="http://blog.jeffdouglas.com/2010/07/14/attach-a-pdf-to-a-record-in-salesforce/attach-pdf/" rel="attachment wp-att-2867"><img src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/attach-pdf.png" alt="" title="attach-pdf" width="500" class="alignnone size-full wp-image-2867" /></a></p>
<p><strong>PdfGenerator Visualforce Page</strong></p>
<p>The Visualforce page allows the users to enter the ID of the Account to attach the PDF to as well as the name of the PDF. You could just have easily used a Controller Extension instead of entering the ID for the Account but I went this route for simplicity.</p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>page controller<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;PdfGeneratorController&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>sectionHeader title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;PDF Example&quot;</span> subtitle<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Attach a PDF&quot;</span> 
    description<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Example of how to attach a PDF to a record.&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>form <span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlock title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;PDF Input&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockButtons <span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>commandButton action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!savePdf}&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Save PDF&quot;</span><span style="color: #339933;">/&gt;</span>
      <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockButtons<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageMessages <span style="color: #339933;">/&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockSection <span style="color: #339933;">&gt;</span>
&nbsp;
        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem <span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>outputLabel value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;File Name&quot;</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pdfName&quot;</span><span style="color: #339933;">/&gt;</span>
          <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>inputText value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!pdfName}&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pdfName&quot;</span><span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem<span style="color: #339933;">&gt;</span>
&nbsp;
        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem <span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>outputLabel value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Account ID&quot;</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #339933;">/&gt;</span>
          <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>inputText value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!parentId}&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockSectionItem<span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockSection<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlock<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>page<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</p>
<p><strong>PdfGeneratorController Custom Controller</strong></p>
<p>The Controller passes the Account ID that the user entered as a parameter for the Visualforce page being generated. It then creates a new Attachment object and sets some attributes. It sets the ParentId to the value of the Account ID that the user entered so that the PDF is attached to that record. The Body of the attachment uses the Blob returned from the PageReference&#8217;s getContent method. You could also use the getContentAsPDF method which always returns the page as a PDF, regardless of the &lt;apex:page&gt; component&#8217;s renderAs attribute. However, this method <strong>always</strong> seems to throw an error in the test class. See the <a href="http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_pagereference.htm" target="_blank">PageReference documentation</a> for more info. The method then redirects the user to the Account page so they can view the PDF attachment.</p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> with sharing <span style="color: #000000; font-weight: bold;">class</span> PdfGeneratorController <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> ID parentId <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> <span style="color: #003399;">String</span> pdfName <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> PageReference savePdf<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    PageReference pdf <span style="color: #339933;">=</span> Page.<span style="color: #006633;">PdfGeneratorTemplate</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// add parent id to the parameters for standardcontroller</span>
    pdf.<span style="color: #006633;">getParameters</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span>,parentId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// create the new attachment</span>
    Attachment attach <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Attachment<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// the contents of the attachment from the pdf</span>
    <span style="color: #003399;">Blob</span> body<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// returns the output of the page as a PDF</span>
    	body <span style="color: #339933;">=</span> pdf.<span style="color: #006633;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// need to pass unit test -- current bug	</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>VisualforceException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    	body <span style="color: #339933;">=</span> <span style="color: #003399;">Blob</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Some Text'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    attach.<span style="color: #006633;">Body</span> <span style="color: #339933;">=</span> body<span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// add the user entered name</span>
    attach.<span style="color: #003399;">Name</span> <span style="color: #339933;">=</span> pdfName<span style="color: #339933;">;</span>
    attach.<span style="color: #006633;">IsPrivate</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// attach the pdf to the account</span>
    attach.<span style="color: #006633;">ParentId</span> <span style="color: #339933;">=</span> parentId<span style="color: #339933;">;</span>
    insert attach<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// send the user to the account to view results</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> PageReference<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">+</span>parentId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</p>
<p><strong>PdfGeneratorTemplate Visualforce Page</strong></p>
<p>This is the Visualforce page that is generated in the Controller. It simply uses the StandardController and displays the Account name for the ID passed to it.
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>page standardController<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Account&quot;</span> renderAs<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pdf&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span>Congratulations<span style="color: #339933;">!!&lt;/</span>h1<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>You created a PDF <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#123;</span><span style="color: #339933;">!</span>account.<span style="color: #006633;">name</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>page<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</p>
<p><b>Test Class</b></p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">@isTest
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> Test_PdfGeneratorController <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> Account account<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    account <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Account<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    account.<span style="color: #003399;">Name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Test Account'</span><span style="color: #339933;">;</span>
    insert account<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> testMethod <span style="color: #000066; font-weight: bold;">void</span> testPdfGenerator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    PageReference pref <span style="color: #339933;">=</span> Page.<span style="color: #006633;">PdfGenerator</span><span style="color: #339933;">;</span>
    pref.<span style="color: #006633;">getParameters</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span>,account.<span style="color: #006633;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Test.<span style="color: #006633;">setCurrentPage</span><span style="color: #009900;">&#40;</span>pref<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    PdfGeneratorController con <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PdfGeneratorController<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
&nbsp;
    Test.<span style="color: #006633;">startTest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// populate the field with values</span>
    con.<span style="color: #006633;">parentId</span> <span style="color: #339933;">=</span> account.<span style="color: #006633;">id</span><span style="color: #339933;">;</span>
    con.<span style="color: #006633;">pdfName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'My Test PDF'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// submit the record</span>
    pref <span style="color: #339933;">=</span> con.<span style="color: #006633;">savePdf</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// assert that they were sent to the correct page</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">assertEquals</span><span style="color: #009900;">&#40;</span>pref.<span style="color: #006633;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,<span style="color: #0000ff;">'/'</span><span style="color: #339933;">+</span>account.<span style="color: #006633;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// assert that an attachment exists for the record</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #009900;">&#91;</span>select count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> from attachment where parentId <span style="color: #339933;">=</span> <span style="color: #339933;">:</span>account.<span style="color: #006633;">id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    Test.<span style="color: #006633;">stopTest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeffdouglas.com/2010/07/14/attach-a-pdf-to-a-record-in-salesforce/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Building a Dynamic Search Page in Visualforce</title>
		<link>http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=building-a-dynamic-search-page-in-visualforce</link>
		<comments>http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 10:31:34 +0000</pubDate>
		<dc:creator>Jeff Douglas</dc:creator>
				<category><![CDATA[Apex]]></category>
		<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Visualforce]]></category>

		<guid isPermaLink="false">http://blog.jeffdouglas.com/?p=2778</guid>
		<description><![CDATA[I brushed this code off and thought it might be useful to someone as a starting point for a dynamic search page. It has some cool functionality including passing search criteria via Javascript to the controller, search as you type, sorting of results by clicking on the column header plus much more. Hope you find [...]]]></description>
			<content:encoded><![CDATA[<p>I brushed this code off and thought it might be useful to someone as a starting point for a dynamic search page. It has some cool functionality including passing search criteria via Javascript to the controller, search as you type, sorting of results by clicking on the column header plus much more. Hope you find it useful.</p>
<h3 style="text-decoration:underline"><a href="https://jeffdouglas-developer-edition.na5.force.com/examples/CustomerSearch" target="_blank"><font class="Apple-style-span" color="#000000">You can run this demo at my developer site.</font></a></h3>
<p><a href="https://jeffdouglas-developer-edition.na5.force.com/examples/CustomerSearch"><img src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/customer-search.png" alt="" title="customer-search" width="500" class="alignnone size-full wp-image-2782" /></a></p>
<p>Some of the interesting features of the Visualforce page and Apex controller include:
<ul>
<li>Instead of the typical overhead of using getters/setters in the controller to maintain the variables for the search form, I used <a href="http://blog.sforce.com/sforce/2009/10/passing-javascript-values-to-apex-controller.html" target="_blank">Dave Carroll&#8217;s blog</a> as an example to pass the variables via Javascript.</li>
<li>Since I&#8217;m using Javascript to pass my parameters, I can get fancy and make the search form more dynamic by running the search as the user types or selects an option in the picklist. No submit button is required.</li>
<li>Users can click on the column headers to toggle the direction of the search results by using a CommandLink component and passing the column name.</li>
<li>Build the picklist using Dynamic Apex&#8217;s <a href="http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_describe_objects_understanding.htm" target="_blank">Describe functionality</a> so that it&#8217;s maintenance free.</li>
<li>Perform the search against multiple fields including multi-select picklists using dynamic SOQL and preventing SOQL injection attacks.</li>
</ul>
<p><b>ContactSearchController</b></p>
<p>Take a look at the Apex code below. The search interaction is split up between two separate but integral parts. When the search is fired from the Visualforce page via Javascript, the SOQL is constructed in the runSearch() method and is then passed to the runQuery() method to execute. The SOQL string is persisted so that when the user clicks on the table column the same SOQL can be issued again in the toggleSort() method but ordered by a different field name and sort direction.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> with sharing <span style="color: #000000; font-weight: bold;">class</span> ContactSearchController <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// the soql without the order and limit</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> soql <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: #666666; font-style: italic;">// the collection of contacts to display</span>
  <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Contact<span style="color: #339933;">&gt;</span> contacts <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: #666666; font-style: italic;">// the current sort direction. defaults to asc</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> sortDir <span style="color: #009900;">&#123;</span>
    get  <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sortDir <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  sortDir <span style="color: #339933;">=</span> <span style="color: #0000ff;">'asc'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">return</span> sortDir<span style="color: #339933;">;</span>  <span style="color: #009900;">&#125;</span>
    set<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// the current field to sort by. defaults to last name</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> sortField <span style="color: #009900;">&#123;</span>
    get  <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sortField <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>sortField <span style="color: #339933;">=</span> <span style="color: #0000ff;">'lastName'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">return</span> sortField<span style="color: #339933;">;</span>  <span style="color: #009900;">&#125;</span>
    set<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// format the soql for display on the visualforce page</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> debugSoql <span style="color: #009900;">&#123;</span>
    get <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> soql <span style="color: #339933;">+</span> <span style="color: #0000ff;">' order by '</span> <span style="color: #339933;">+</span> sortField <span style="color: #339933;">+</span> <span style="color: #0000ff;">' '</span> <span style="color: #339933;">+</span> sortDir <span style="color: #339933;">+</span> <span style="color: #0000ff;">' limit 20'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    set<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// init the controller and display some sample data when the page loads</span>
  <span style="color: #000000; font-weight: bold;">public</span> ContactSearchController<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    soql <span style="color: #339933;">=</span> <span style="color: #0000ff;">'select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null'</span><span style="color: #339933;">;</span>
    runQuery<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: #666666; font-style: italic;">// toggles the sorting of query from asc&lt;--&gt;desc</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> toggleSort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// simply toggle the direction</span>
    sortDir <span style="color: #339933;">=</span> sortDir.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #0000ff;">'desc'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'asc'</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// run the query again</span>
    runQuery<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: #666666; font-style: italic;">// runs the actual query</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> runQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
      contacts <span style="color: #339933;">=</span> Database.<span style="color: #006633;">query</span><span style="color: #009900;">&#40;</span>soql <span style="color: #339933;">+</span> <span style="color: #0000ff;">' order by '</span> <span style="color: #339933;">+</span> sortField <span style="color: #339933;">+</span> <span style="color: #0000ff;">' '</span> <span style="color: #339933;">+</span> sortDir <span style="color: #339933;">+</span> <span style="color: #0000ff;">' limit 20'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      ApexPages.<span style="color: #006633;">addMessage</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ApexPages.<span style="color: #006633;">Message</span><span style="color: #009900;">&#40;</span>ApexPages.<span style="color: #006633;">Severity</span>.<span style="color: #006633;">ERROR</span>, <span style="color: #0000ff;">'Ooops!'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// runs the search with parameters passed via Javascript</span>
  <span style="color: #000000; font-weight: bold;">public</span> PageReference runSearch<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #003399;">String</span> firstName <span style="color: #339933;">=</span> Apexpages.<span style="color: #006633;">currentPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getParameters</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'firstname'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">String</span> lastName <span style="color: #339933;">=</span> Apexpages.<span style="color: #006633;">currentPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getParameters</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lastname'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">String</span> accountName <span style="color: #339933;">=</span> Apexpages.<span style="color: #006633;">currentPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getParameters</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'accountName'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">String</span> technology <span style="color: #339933;">=</span> Apexpages.<span style="color: #006633;">currentPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getParameters</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'technology'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    soql <span style="color: #339933;">=</span> <span style="color: #0000ff;">'select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>firstName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      soql <span style="color: #339933;">+=</span> <span style="color: #0000ff;">' and firstname LIKE <span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: #339933;">+</span><span style="color: #003399;">String</span>.<span style="color: #006633;">escapeSingleQuotes</span><span style="color: #009900;">&#40;</span>firstName<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">'%<span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>lastName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      soql <span style="color: #339933;">+=</span> <span style="color: #0000ff;">' and lastname LIKE <span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: #339933;">+</span><span style="color: #003399;">String</span>.<span style="color: #006633;">escapeSingleQuotes</span><span style="color: #009900;">&#40;</span>lastName<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">'%<span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>accountName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      soql <span style="color: #339933;">+=</span> <span style="color: #0000ff;">' and account.name LIKE <span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: #339933;">+</span><span style="color: #003399;">String</span>.<span style="color: #006633;">escapeSingleQuotes</span><span style="color: #009900;">&#40;</span>accountName<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">'%<span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: #339933;">;</span>  
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>technology.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      soql <span style="color: #339933;">+=</span> <span style="color: #0000ff;">' and interested_technologies__c includes (<span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: #339933;">+</span>technology<span style="color: #339933;">+</span><span style="color: #0000ff;">'<span style="color: #000099; font-weight: bold;">\'</span>)'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// run the query again</span>
    runQuery<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;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// use apex describe to build the picklist values</span>
  <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> technologies <span style="color: #009900;">&#123;</span>
    get <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>technologies <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        technologies <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Schema.<span style="color: #006633;">DescribeFieldResult</span> field <span style="color: #339933;">=</span> Contact.<span style="color: #006633;">interested_technologies__c</span>.<span style="color: #006633;">getDescribe</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>Schema.<span style="color: #006633;">PicklistEntry</span> f <span style="color: #339933;">:</span> field.<span style="color: #006633;">getPicklistValues</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
          technologies.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">getLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">return</span> technologies<span style="color: #339933;">;</span>          
    <span style="color: #009900;">&#125;</span>
    set<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><b>CustomerSearch Visualforce Page</b></p>
<p>The Visualforce page has three sections: 1) a search form, 2) a results blockTable and 3) a debug panel displaying the SOQL that was executed. </p>
<p>The search form has a number of fields that fire the Javascript search using the onkeyup and onchange events. Instead of each form field passing the current values to actionFunction&#8217;s Javascript method, for ease of use, each form field calls the doSearch() function that gathers up the values and submits them. When the actionFunction renders it creates a Javascript function that POSTs the values to the controller in the same manner as CommandLink or CommandButton. </p>
<p>The search results BlockTable is rerendered when the search is submitted to the controller so that the results display properly. Users can click on the column headers to reorder the results of the query. This uses a CommandLink to pass the sort field to the controller and toggle the sort direction.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>page controller<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ContactSearchController&quot;</span> sidebar<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;false&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>form <span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageMessages id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;errors&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlock title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Find Me A Customer!&quot;</span> mode<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;edit&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>table width<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;100%&quot;</span> border<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>  
    <span style="color: #339933;">&lt;</span>td width<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;200&quot;</span> valign<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;top&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlock title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Parameters&quot;</span> mode<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;edit&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;criteria&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
      function doSearch<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        searchServer<span style="color: #009900;">&#40;</span>
          document.<span style="color: #006633;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;firstName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">value</span>,
          document.<span style="color: #006633;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;lastName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">value</span>,
          document.<span style="color: #006633;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;accountName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">value</span>,
          document.<span style="color: #006633;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;technology&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">options</span><span style="color: #009900;">&#91;</span>document.<span style="color: #006633;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;technology&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">selectedIndex</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">value</span>
          <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span> 
&nbsp;
      <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>actionFunction name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;searchServer&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!runSearch}&quot;</span> rerender<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;results,debug,errors&quot;</span><span style="color: #339933;">&gt;</span>
          <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>param name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;firstName&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;</span>
          <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>param name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;lastName&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;</span>
          <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>param name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;accountName&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;</span>
          <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>param name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;technology&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;</span>
      <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>actionFunction<span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>table cellpadding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2&quot;</span> cellspacing<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>td style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;font-weight:bold;&quot;</span><span style="color: #339933;">&gt;</span>First Name<span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;firstName&quot;</span> onkeyup<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;doSearch();&quot;</span><span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>td style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;font-weight:bold;&quot;</span><span style="color: #339933;">&gt;</span>Last Name<span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;lastName&quot;</span> onkeyup<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;doSearch();&quot;</span><span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>td style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;font-weight:bold;&quot;</span><span style="color: #339933;">&gt;</span>Account<span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;accountName&quot;</span> onkeyup<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;doSearch();&quot;</span><span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>td style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;font-weight:bold;&quot;</span><span style="color: #339933;">&gt;</span>Interested Technologies<span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
          <span style="color: #339933;">&lt;</span>select id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;technology&quot;</span> onchange<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;doSearch();&quot;</span><span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>option<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>repeat value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!technologies}&quot;</span> var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tech&quot;</span><span style="color: #339933;">&gt;</span>
              <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!tech}&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">!</span>tech<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>repeat<span style="color: #339933;">&gt;</span>
          <span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlock<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>td valign<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;top&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlock mode<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;edit&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;results&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlockTable value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!contacts}&quot;</span> var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contact&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>column <span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>facet name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;header&quot;</span><span style="color: #339933;">&gt;</span>
                    <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>commandLink value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;First Name&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!toggleSort}&quot;</span> rerender<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;results,debug&quot;</span><span style="color: #339933;">&gt;</span>
                        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>param name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sortField&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;firstName&quot;</span> assignTo<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!sortField}&quot;</span><span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>commandLink<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>facet<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>outputField value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!contact.firstName}&quot;</span><span style="color: #339933;">/&gt;</span>
            <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>column<span style="color: #339933;">&gt;</span>
&nbsp;
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>column <span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>facet name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;header&quot;</span><span style="color: #339933;">&gt;</span>
                    <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>commandLink value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Last Name&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!toggleSort}&quot;</span> rerender<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;results,debug&quot;</span><span style="color: #339933;">&gt;</span>
                        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>param name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sortField&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;lastName&quot;</span> assignTo<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!sortField}&quot;</span><span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>commandLink<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>facet<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>outputField value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!contact.lastName}&quot;</span><span style="color: #339933;">/&gt;</span>
            <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>column<span style="color: #339933;">&gt;</span>
&nbsp;
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>column <span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>facet name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;header&quot;</span><span style="color: #339933;">&gt;</span>
                    <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>commandLink value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Account&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!toggleSort}&quot;</span> rerender<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;results,debug&quot;</span><span style="color: #339933;">&gt;</span>
                        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>param name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sortField&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;account.name&quot;</span> assignTo<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!sortField}&quot;</span><span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>commandLink<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>facet<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>outputField value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!contact.account.name}&quot;</span><span style="color: #339933;">/&gt;</span>
            <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>column<span style="color: #339933;">&gt;</span>
&nbsp;
            <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>column <span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>facet name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;header&quot;</span><span style="color: #339933;">&gt;</span>
                    <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>commandLink value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Technologies&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!toggleSort}&quot;</span> rerender<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;results,debug&quot;</span><span style="color: #339933;">&gt;</span>
                        <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>param name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sortField&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;interested_technologies__c&quot;</span> assignTo<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!sortField}&quot;</span><span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>commandLink<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>facet<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>outputField value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!contact.Interested_Technologies__c}&quot;</span><span style="color: #339933;">/&gt;</span>
            <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>column<span style="color: #339933;">&gt;</span>
&nbsp;
        <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlockTable<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlock<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>pageBlock title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Debug - SOQL&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;debug&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>apex<span style="color: #339933;">:</span>outputText value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{!debugSoql}&quot;</span> <span style="color: #339933;">/&gt;</span>           
  <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlock<span style="color: #339933;">&gt;</span>    
&nbsp;
  <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>pageBlock<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>apex<span style="color: #339933;">:</span>page<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>My Favorite Salesforce.com Summer &#8217;10 Features</title>
		<link>http://blog.jeffdouglas.com/2010/07/07/my-favorite-salesforce-com-summer-10-features/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=my-favorite-salesforce-com-summer-10-features</link>
		<comments>http://blog.jeffdouglas.com/2010/07/07/my-favorite-salesforce-com-summer-10-features/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 16:38:00 +0000</pubDate>
		<dc:creator>Jeff Douglas</dc:creator>
				<category><![CDATA[Salesforce]]></category>

		<guid isPermaLink="false">http://blog.jeffdouglas.com/?p=2763</guid>
		<description><![CDATA[The Summer 10 release was rolled out last month and I&#8217;m finally getting a chance to go through the entire release notes and pick out some of my favorite new features and enhancements. Sorry for the delay but I&#8217;ve been busy with stuff. I didn’t hit all of the items in the release notes so [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jeffdouglas.com/2010/07/07/my-favorite-salesforce-com-summer-10-features/"><img src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/summer10-logo.jpeg" alt="" title="summer10-logo" width="480" height="108" class="alignnone size-full wp-image-2768" /></a></p>
<p>The Summer 10 release was rolled out last month and I&#8217;m finally getting a chance to go through the entire <a href="http://na1.salesforce.com/help/doc/en/salesforce_summer10_release_notes.pdf" target="_blank">release notes</a> and pick out some of my favorite new features and enhancements. Sorry for the delay but I&#8217;ve been busy with stuff. I didn’t hit all of the items in the release notes so make sure you pull up the the PDF and check out all of the goodies in detail.</p>
<p><b>Chatter </b></p>
<p>If you didn&#8217;t hear that Chatter went GA then you are probably dead. Stop reading this and roll over in your grave. They also released the functionality to setup public or private groups to collaborate with specific people and you can use it with Content and Knowledge. Chatter must be enabled and setup for your org. For more info on Chatter check out <a href="http://www.salesforce.com/chatter" target="_blank">this page</a>.</p>
<p><b>Custom Cloud Enhancements</b></p>
<p>
<ul>
<li>You can new also set up dynamic dashboards which run using the security settings of the logged-in user instead of a static running user.</li>
<li>Drag-and-drop dashboard builder to simply drag a component type onto a column and then drop a data source onto it. Much easier and more powerful.</li>
<li>You can show column totals on dashboard tables for up to four columns.</li>
<li>You can permanently delete records with Data Loader by using the the Hard Delete operation. The deleted records are not stored in the Recycle Bin.</li>
</ul>
<p><b>Force.com Sites Enhancements</b></p>
<p>
<ul>
<li>Rewriting URLs for Sites is now available so that you can make pretty URLs and links for Sites visitors. So instead of seeing a link like http://mysite.force.com/contact?id=0000000000001234567 you can generate a link like http://mysite.force.com/mycontact/MikeSmith.</li>
<li>Troubleshoot errors in Sites easier with the administrator preview option. When accessing a Site in administrator preview mode extra debug info displays at the bottom of the page. FYI: you have to add an extra Visualforce tag to your Sites pages to make this debug info appear outside of standard error pages.</li>
<li>Sites Single Sign-On &#8211; now your identity provider can use SAML with Sites to do single sign-on. Used in conjunction with either a customer or a partner portal.</li>
<li>New Cookie Class for Force.com Sites &#8211; The cookie class lets you access cookies for your Force.com Site using Apex. Use this in conjunction with the new getCookies and setCookies Methods for PageReference to create and store cookies in Apex.</li>
</ul>
<p><b>Apex &amp; Visualforce Enhancements</b></p>
<p>
<ul>
<li>Declarative <a href="http://blog.sforce.com/sforce/2010/05/dependent-picklist-improvements-in-summer-10.html" target="_blank">dependent picklists</a> in Visualforce</li>
<li>Use Sets with both Primitives and sObjects now!</li>
<li>Only available for Apex saved with API v19.0 or later, the sObject Clone method now uses the user running the Apex code for the CreateBy value, and the current date and time for CreatedDate.</li>
<li>New encryption, decryption and key generating methods for the Crypto class.</li>
<li>No more Batch Apex limit for execute method. Used to be able to call the execute method 250,000 times in a 24 hour period per organization. Not any more!</li>
<li>The total heap size has been increased probably in response to the Spring 10 change that collections can hold as many items as the heap allows. Trigger size is now 300,000; an anonymous block, Visualforce controller, or WSDL method, heap size is now 3,000,000; and test method, heap size is now 1,500,000.</li>
<li>SOQL subqueries no longer return records that are marked as IsDeleted unless IsDeleted = true is explicitly stated as part of the query.</li>
<li>Visualforce pages and components created using Salesforce.com API version 19.0 or higher must be written as well-formed XML or they will not save.</li>
</ul>
<p><b>Web Services API Enhancements</b></p>
<p>The following new objects have been added in API version 19.0:</p>
<p>
<ul>
<li>The Article__DataCategorySelection object associates an article with data categories from a data category group. </li>
<li>The QuestionDataCategorySelection object associates a question with a data category from a data category group. </li>
<li>The KnowledgeArticle object provides read–only access to an article independent of its version. </li>
<li>The ApexLog object represents a debug log.</li>
<li>The SlaProcess object represents an entitlement process associated with an entitlement.</li>
<li>A ton of new chatter objects (actually from v18 as part of limited release).</li>
</ul>
<p><b>Bulk API Enhancements</b></p>
<p>
<ul>
<li>Improved retry handling for batch timeout and lock errors so that the Bulk API places the remainder of the failed batch back in the queue for later processing up to 10 times when processing.</li>
<li>Support for relationship fields and polymorphic relationship fields in XML batches.</li>
<li>BatchInfo stateMessage field enhancement so that the stateMessage field now contains all the reasons associated with a Failed batch state. </li>
<li>Permanent deletion of records with the support of a hardDelete option. When this value is specified, deleted records are not kept in the Recycle Bin.</li>
</ul>
<p><b>Sales Cloud Enhancements</b></p>
<p>
<ul>
<li>You can now create alerts to lead and contact owners when the leads and contacts are added to a campaign.</li>
<li>Now you can display lead and contact custom field information on campaign member page layouts with the formula field enhancements.</li>
<li>Salesforce.com displays a warning message if the contact or lead you are sending email to has Email Opt Out equal to true.</li>
<li>If contacts or leads have multiple email addresses, you can new choose which address to use when clicking Send an Email. </li>
<li>You can create personalized footers or disclaimers that appear at the bottom of all outgoing email messages sent from Salesforce.com or the API.</li>
</ul>
<p><b>Community Enhancements</b></p>
<p>
<ul>
<li>Answers community now publically available to Force.com Sites users.</li>
<li>Administrators and trusted community members (with create case permissions) can escalate an unanswered or problematic question to a new case.</li>
<li>Community members (with create Knowledge permissions) can choose to convert a particularly helpful reply into a new article in the knowledge base.</li>
<li>Workflow is now available for questions to help monitor Answers communities.</li>
<li>You can designate certain data categories visible to all users while still restricting access as needed for each role. This was a problem because users without roles (i.e., high-volume Customer Portal users) could only see could only see uncategorized questions.</li>
<li>Members of an answers community can delete their questions and replies now.</li>
</ul>
<p><b>Knowledge Enhancements</b></p>
<p>
<ul>
<li>When closing a case, users can now more quickly create a new draft article that can be reviewed and published automatically to the case and available via knowledge base.</li>
<li>Ability for support reps to quickly send knowledge base articles to contacts via email templates. The template automatically converts articles associated with the case into PDF attachments on an email.</li>
<li>As soon as a new case is saved, if autosuggestion is enabled, a list of potentially relevant articles displays.</li>
<li>Follow Articles in your Chatter feed.</li>
<li>Two new custom report types for the knowledge base are available: Cases with Articles and Knowledge Keyword Search. </li>
<li>Send email to an Article reviewer notifying them that you assign one or more articles to them.</li>
</ul>
<p><b>Salesforce CRM Content</b></p>
<p>The Salesforce CRM Content feature license is included in all organizations at no additional cost but you do have to enable this feature.</p>
<p>
<p><b>Cloud Scheduler</b></p>
<p>The new Cloud Scheduler allows you to schedule meeting with customers and internal resources. Meeting requests send attnedees to a web page where they can select times that are best for them and then respond with multiple options. Salesforce.com tracks all the responses so you can pick the best time to meet when you confirm the meeting. <a href="http://www.youtube.com/watch?v=y4FLMWqcfi4" target="_blank">Here&#8217;s a small video demo</a>.</p>
</p>
<p><b>Enabling High Volume Customer Portal Users</b></p>
<p>You can now enable contacts as High Volume Customer Portal users so they can log in to a Customer Portal without affecting its performance. High-volume Customer Portal users include both the High Volume Customer Portal User and Authenticated Website User license types. The High Volume Customer Portal User user license is currently available through a pilot program, while the Authenticated Website User user license is GA.</p>
<p><b>Mobile Enhancements</b></p>
<p><i>Blackberry</i></p>
<p>
<ul>
<li>Improved related list search.</li>
<li>Report tab is no longer hard-coded on Blackberries and is now configuratble by administrators.</li>
</ul>
<p><i>iPhone</i></p>
<p>
<ul>
<li>Support for both local and remote search for records.</li>
<li>Performance improvements for large data sets and synchronizing.</li>
</ul>
<p><i>Windows Mobile</i></p>
<p>
<ul>
<li>Peripheral support to provide integration with the barcode scanners and magnetic stripe card readers in select Motorola Windows Mobile devices.</li>
<li>Support for viewing attachments in related list and attaching images to records.</li>
</ul>
<p><b>Push Patch Updates</b> (Developer Edition only)</p>
<p>You can develop a new package type called a patch version, which enables a developer to change the functionality of existing components in a managed package, while ensuring that subscribers experience no visible changes to the package. Patch versions can only be created for major release packages. Subscribers can receive patch upgrades just like any other package version. However, you can also distribute a patch by using push upgrades to automatically upgrade all eligible customers running the same major release.</p>
<h3>Betas Programs</h3>
<p><b>Dependent Lookups and Other Lookup Filters Enhancements</b></p>
<p>Lookup filters are administrator settings that restrict the valid values and lookup dialog results for lookup, master-detail, and hierarchical relationship fields. Administrators specify the restrictions by configuring filter criteria that compare fields and values on the source record; target object; the user&#8217;s record, profile, and role and the target object&#8217;s records.</p>
<p>
<ul>
<li>Dependent Lookups &#8211; A dependent lookup is a relationship field with a lookup filter that references fields on the source object. Similar to dependent picklists, the valid values in the dependent lookup change according to other values the user enters on the record.</li>
<li>Related Lookup Filters Lists for Target Objects &#8211; You can quickly see a list of the lookup filters that restrict the values of each target object. This is useful when creating similar filters for a target object. Also, lookup filters that reference fields on related objects count against the cross-object reference limit, which is the number of unique relationships allowed for a target object. The Related Lookup Filters list lets you see which lookup filters might impact that limit.</li>
</ul>
<p><b>Quotes Template Editor</b></p>
<p>The quote template editor looks and functions a lot like the enhanced page layout editor with drag &#8216;n drop functionality. Sales reps can choose either a standard quote template or a custom template and send out quote PDFs to customers.</p>
<h3>Pilot Programs</h3>
<p><b>Chatter for Mobile</b></p>
<p>Access Chatter from your BlackBerry or iPhone. The mobile application only consists of the Chatter, Profile, and People tabs. Android support &#8220;promised&#8221; by the end of the year.</p>
<p><b>New Opportunity Page</b></p>
<p>Customize how your Opportunity page looks with the New Opportunity Page pilot. Drag &#8216;n drop side tabs let you quickly and easily navigate and personalize your page to highlight information that is the most valuable to you.</p>
<p><b>Improved System Log Console (Apex CSI) </b></p>
<p>A new context-sensitive execution viewer, showing the source of an operation in a transaction, what triggered that operation, and what occurred afterward. You can use it for tracking code execution, workflow, validation rules, and other operations that were executed during the transaction.</p>
<p><b>Visualforce View State Inspector</b></p>
<p>The View State Inspector lets you view which Visualforce elements are contributing to the size of your view state. You can use this to monitor the performance of Visualforce pages where users submit data using forms. By minimizing your view state size, you can reduce load times.</p>
<p><b>Previews for Microsoft Office 2007 Files</b></p>
<p>The new document viewer allows users to view Microsoft Office 2007 files, including PowerPoint, Word, and Excel without downloading, whether the document is a content delivery sent to a lead, prospect, or colleague, or a document viewed internally in Salesforce CRM Content.</p>
<h3>Developer Previews</h3>
<p><b>Report Builder Enhancements</b></p>
<p>A new Developer Preview sports a more powerful report builder. Now you can create and edit summary reports, manage custom and advanced filters, and edit row count limits for tabular reports. Use the drag-and-drop interface to reorder columns, add and rearrange groupings, and change date granularities. For Developer Preview, report builder only works with tabular and summary reports, and functionality is limited. You can&#8217;t use it for matrix reports or charts. <strong>Update from Thomas Tobin at Salesforce.com</strong>: &#8220;We are updating the report builder, and charts are going to be creatable/editable in the report builder tomorrow evening.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeffdouglas.com/2010/07/07/my-favorite-salesforce-com-summer-10-features/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Using RSA-SHA1 with Salesforce Crypto Class</title>
		<link>http://blog.jeffdouglas.com/2010/07/06/using-rsa-sha1-with-salesforce-crypto-class/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-rsa-sha1-with-salesforce-crypto-class</link>
		<comments>http://blog.jeffdouglas.com/2010/07/06/using-rsa-sha1-with-salesforce-crypto-class/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 21:28:31 +0000</pubDate>
		<dc:creator>Jeff Douglas</dc:creator>
				<category><![CDATA[Apex]]></category>
		<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Salesforce]]></category>

		<guid isPermaLink="false">http://blog.jeffdouglas.com/?p=2754</guid>
		<description><![CDATA[This is a rather obscure post but it will definitely come in handy to someone trying to use the RSA-SHA1 algorithm with the Salesforce Crypto class. I&#8217;m spent the past two days trying to hook up OAuth using Apex and various Google Services. The standard HMAC-SHA1 algorithm is fairly straight forward with OAuth and Google [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both">This is a rather obscure post but it will definitely come in handy to someone trying to use the RSA-SHA1 algorithm with the Salesforce Crypto class. I&#8217;m spent the past two days trying to hook up OAuth using Apex and various Google Services. The standard HMAC-SHA1 algorithm is fairly straight forward with OAuth and Google but when you are required to register a domain and upload a certificate&#8230; well things get somewhat hairy. There&#8217;s very little documentation on the RSA-SHA2 algorithm and I could only find one relevant post on the topic.</p>
<p style="clear: both">According to the <a href="http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_crypto.htm">Crypto docs</a>, the arguments for the <strong><u>sign</u></strong> method are an algorithm name (i.e., RSA-SHA1), an input Blob (the string to encrypt) and a privateKey Blob. The value of privateKey must be decoded using the EncodingUtilbase64Decode method, and should be in <a href="http://www.rsa.com/rsalabs/node.asp?id=2130" target="_blank">RSA&#8217;s PKCS #8 (1.2) Private-Key Information Syntax Standard form</a>. </p>
<p style="clear: both">The sample code from the docs doesn&#8217;t help determining how to obtain the privateKey:</p>
<p style="clear: both">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> algorithmName <span style="color: #339933;">=</span> <span style="color: #0000ff;">'RSA'</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> key <span style="color: #339933;">=</span> <span style="color: #0000ff;">'pkcs8 format private key'</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Blob</span> privateKey <span style="color: #339933;">=</span> EncodingUtil.<span style="color: #006633;">base64Decode</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Blob</span> input <span style="color: #339933;">=</span> <span style="color: #003399;">Blob</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'12345qwerty'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Crypto.<span style="color: #006633;">sign</span><span style="color: #009900;">&#40;</span>algorithmName, input, privateKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p style="clear: both">So after a couple of days of trial and error, swearing and sticking needles in my eyes, I finally came up with the solution for Google. It may not apply to other services but the methodology is roughly the same for the privateKey.</p>
<p style="clear: both">The first step is to generate a self-signing public certificate and private key. You can find more info <a href="http://code.google.com/apis/gdata/docs/auth/authsub.html#Registered" target="_blank">here</a>. Open terminal and run the following:</p>
<p style="clear: both; font-family: Verdana;">openssl req -x509 -nodes -days 365 -newkey rsa:1024 -shal -subj &#8216;/C=US/ST=CA/L=San Mateo/CN=www.appirio.com&#8217; -keyout key-mycompanyrsa.pem -out cert-mycompanyrsa.pem</p>
<p style="clear: both">This will spit out a cert file (cert-mycompanyrsa.pem) and private key file (key-mycompanyrsa.pem). Then upload the cert to your domain for the <a href="https://www.google.com/accounts/ManageDomains" target="_blank">Google account</a>. This will generate a consumer key and a consumer secret for your application.</p>
<p style="clear: both">Now here was my mistake. I was opening the private key file (key-mycompanyrsa.pem) and using the contents of this file in my Apex code for the privateKey Blob value. Google was choking when creating the OAuth request token saying that the signature was incorrect: <strong><em>signature_invalid</em></strong>.</p>
<p style="clear: both">Here&#8217;s the fix. You need to use the private key file (key-mycompanyrsa.pem) with the openssl pkcs8 command to process the private keys into PKCS#8 format.</p>
<p style="clear: both">Open terminal again and run:</p>
<p style="clear: both; font-family: Verdana;">openssl pkcs8 -topk8 -nocrypt -in key-mycompanyrsa.pem -outform PEM</p>
<p style="clear: both">This will display a new private key in terminal and <strong><em>THIS</em></strong> is the value you use for the privateKey argument for the sign method. Just copy everything betweek the &#8220;begin&#8221; line and &#8220;end&#8221; line.</p>
<p style="clear: both"><a href="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/privatekey.png" class="image-link" rel="lightbox[2754]"><img class="linked-to-original" src="http://blog.jeffdouglas.com/wp-content/uploads/2010/07/privatekey-thumb.png" height="275" align="left" width="380" style=" display: inline; float: left; margin: 0 10px 10px 0;" /></a></p>
<p><br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeffdouglas.com/2010/07/06/using-rsa-sha1-with-salesforce-crypto-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding the Force.com Multitenant Architecture</title>
		<link>http://blog.jeffdouglas.com/2010/07/02/understanding-the-force-com-multitenant-architecture/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=understanding-the-force-com-multitenant-architecture</link>
		<comments>http://blog.jeffdouglas.com/2010/07/02/understanding-the-force-com-multitenant-architecture/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 12:25:38 +0000</pubDate>
		<dc:creator>Jeff Douglas</dc:creator>
				<category><![CDATA[Salesforce]]></category>

		<guid isPermaLink="false">http://blog.jeffdouglas.com/?p=2749</guid>
		<description><![CDATA[I was doing some research for our new book, The Salesforce Handbook, and came across a whitepaper entitled, The Force.com Multitenant Architecture Understanding the Design of Salesforce.com’s Internet Application Development Platform This whitepaper is a great read if you are interested in the guts of the Force.com platform and how it works. It talks about [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both">I was doing some research for our new book, <a href="http://salesforcehandbook.wordpress.com/" target="_blank">The Salesforce Handbook</a>, and came across a whitepaper entitled,</p>
<p style="clear: both"><strong>The Force.com Multitenant Architecture </strong><br /><em>Understanding the Design of Salesforce.com’s Internet Application Development Platform</em></p>
<p style="clear: both">This whitepaper is a great read if you are interested in the guts of the Force.com platform and how it works. It talks about multitenant application design and metadata driven architectures from a high level. It offers some really great insights on how data is stored and retrieved on the platform and well as application development, logic and processing.</p>
<p style="clear: both">You can download the whitepaper <a href="http://wiki.developerforce.com/index.php/Multi_Tenant_Architecture " target="_blank">here</a>. </p>
<p><br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jeffdouglas.com/2010/07/02/understanding-the-force-com-multitenant-architecture/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
