<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>I Write Crappy Code</title>
	<atom:link href="http://iwritecrappycode.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://iwritecrappycode.wordpress.com</link>
	<description>Oh my god. It&#039;s full of code!</description>
	<lastBuildDate>Wed, 25 Jan 2012 19:16:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='iwritecrappycode.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/57bd20de17f92d06f6677c4e53d915d9?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>I Write Crappy Code</title>
		<link>http://iwritecrappycode.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://iwritecrappycode.wordpress.com/osd.xml" title="I Write Crappy Code" />
	<atom:link rel='hub' href='http://iwritecrappycode.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Reliably injecting jQuery and jQuery UI with callback!</title>
		<link>http://iwritecrappycode.wordpress.com/2012/01/25/reliably-injecting-jquery-and-jquery-ui-with-callback/</link>
		<comments>http://iwritecrappycode.wordpress.com/2012/01/25/reliably-injecting-jquery-and-jquery-ui-with-callback/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 19:16:09 +0000</pubDate>
		<dc:creator>kenji776</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[callback]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[Inject]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://iwritecrappycode.wordpress.com/?p=434</guid>
		<description><![CDATA[Hey all, So this is kind of a cool thing. Sometimes you end up needing to inject jQuery in a page (like with advanced custom buttons in Salesforce) or in other cirumstances where you can write scripts, but you don&#8217;t have direct access to the source doc. Some of these times you want to include [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=434&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey all,<br />
So this is kind of a cool thing. Sometimes you end up needing to inject jQuery in a page (like with advanced custom buttons in Salesforce) or in other cirumstances where you can write scripts, but you don&#8217;t have direct access to the source doc. Some of these times you want to include jQuery, along with jQuery UI and it&#8217;s CSS. Most of us know you can use the head.addScript function of javascript to inject the code, but how do you know when it&#8217;s loaded? How do you make sure you only load the UI library after the core library has loaded? Well worry no more, as I have an awesome javascript function here to reliably inject jQuery and the UI and then call a function of your choosing. Here ya go!</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">function loadJQuery(callback)
{
    try
    {
        if(typeof jQuery == &quot;undefined&quot; &#124;&#124; typeof jQuery.ui == &quot;undefined&quot;)
        {
            var maxLoadAttempts = 10;
            var jQueryLoadAttempts = 0;
            //We want to use jQuery as well as the UI elements, so first lets load the stylesheet by injecting it into the dom.
            var head= document.getElementsByTagName('head')[0];
            var v_css  = document.createElement('link');
            v_css.rel = 'stylesheet'
            v_css.type = 'text/css';
            v_css.href = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/redmond/jquery-ui.css';
            head.appendChild(v_css);

            //Okay, now we need the core jQuery library, lets fetch that and inject it into the dom as well
            var script= document.createElement('script');
            script.type= 'text/javascript';
            script.src= 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
            head.appendChild(script);

            checkjQueryLoaded = setInterval(function()
            {
                if(typeof jQuery != &quot;undefined&quot;)
                {
                    //Okay, now we need the core jQuery UI library, lets fetch that and inject it into the dom as well
                    var script= document.createElement('script');
                    script.type= 'text/javascript';
                    script.src= 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js';
                    head.appendChild(script);
                    window.clearInterval(checkjQueryLoaded);
                }
                else if(maxLoadAttempts &lt; jQueryLoadAttempts)
                {
                    window.clearInterval(checkjQueryLoaded);
                }
                jQueryLoadAttempts++;
            },300);

            jQueryLoadAttempts = 0;        

            checkLoaded = setInterval(function()
            {
                if(typeof jQuery != &quot;undefined&quot; &amp;&amp; typeof jQuery.ui != &quot;undefined&quot;)
                {
                    window.clearInterval(checkLoaded);
                    callback(true);
                }
                else if(maxLoadAttempts &lt; jQueryLoadAttempts)
                {
                    window.clearInterval(checkLoaded);
                    callback(false);
                }
                jQueryLoadAttempts++;
            },500);
        }
    }
    catch(exception)
    {
        callback(false);
    }
}
</pre>
<p>Then you can invoke it and have a callback like this</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">loadJQuery(function(loadSuccess){
    if(loadSuccess)
    {
	//Do your jQuery stuff here. Basically you can think of this as a replacement for your
	//document.onReady code
        $(document.getElementsByTagName('body')[0]).append(&quot;&lt;div id=infoNotice title='Success'&gt;jQuery and jQuery UI loaded!&lt;/div&gt;&quot;);
        $( &quot;#infoNotice&quot; ).dialog({ modal: true});
    }
    else
    {
        alert('Couldn\'t load jQuery <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> ');
    }
});
</pre>
<p>Have fun!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iwritecrappycode.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iwritecrappycode.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iwritecrappycode.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iwritecrappycode.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iwritecrappycode.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iwritecrappycode.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iwritecrappycode.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iwritecrappycode.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iwritecrappycode.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iwritecrappycode.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iwritecrappycode.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iwritecrappycode.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iwritecrappycode.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iwritecrappycode.wordpress.com/434/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=434&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iwritecrappycode.wordpress.com/2012/01/25/reliably-injecting-jquery-and-jquery-ui-with-callback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccb9a43d9f22aad88cb8e3471f91af83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kenji776</media:title>
		</media:content>
	</item>
		<item>
		<title>Cloudspokes Simple Timer &amp; Timecard System for Salesforce</title>
		<link>http://iwritecrappycode.wordpress.com/2012/01/24/cloudspokes-simple-timer-timecard-system-for-salesforce/</link>
		<comments>http://iwritecrappycode.wordpress.com/2012/01/24/cloudspokes-simple-timer-timecard-system-for-salesforce/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 06:41:25 +0000</pubDate>
		<dc:creator>kenji776</dc:creator>
				<category><![CDATA[Apex/Visual Force]]></category>
		<category><![CDATA[CloudSpokes]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[challenge]]></category>
		<category><![CDATA[cloudspokes]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Salseforce]]></category>
		<category><![CDATA[timecard]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://iwritecrappycode.wordpress.com/?p=431</guid>
		<description><![CDATA[Hey all, Well another week another Cloudspokes challenge. Sadly it seems the judges were not impressed by my last submission of my jQuery google maps salesforce mashup, so let&#8217;s hope this week goes better. This time around we have a Timer/Timecard system that should allow users in Salesforce to track their interactions with any record [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=431&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey all,<br />
Well another week another Cloudspokes challenge. Sadly it seems the judges were not impressed by my last submission of my jQuery google maps salesforce mashup, so let&#8217;s hope this week goes better. This time around we have a Timer/Timecard system that should allow users in Salesforce to track their interactions with any record during the day, which all rollup and aggregate to a daily timecard. There are some validations that prevent a user from racking up too many hours (based on a field in their profile), having more than one timecard running, and playing with submitted timecards.</p>
<p>The actual link to the challenge is here <a href="http://www.cloudspokes.com/challenges/1358">http://www.cloudspokes.com/challenges/1358</a></p>
<p>This time I also made two videos. One that highlights the functionality, and another that is a quick tech overview of how the thing works.</p>
<p><a href="http://www.screencast.com/t/AoIjojcvBZNP" title="See it in action">See it in action!</a></p>
<p><a href="http://www.screencast.com/t/EVbvH7bPK" title="See how it works">See how it works!</a></p>
<p>If there are any questions I&#8217;d be happy to talk about how I built this, but other than that, I think the videos do a decent job of covering the high points. If they don&#8217;t like this one, well I give up. If I don&#8217;t place, I&#8217;ll be releasing the source code and installable package link. Anyway, wish me luck!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iwritecrappycode.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iwritecrappycode.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iwritecrappycode.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iwritecrappycode.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iwritecrappycode.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iwritecrappycode.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iwritecrappycode.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iwritecrappycode.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iwritecrappycode.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iwritecrappycode.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iwritecrappycode.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iwritecrappycode.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iwritecrappycode.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iwritecrappycode.wordpress.com/431/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=431&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iwritecrappycode.wordpress.com/2012/01/24/cloudspokes-simple-timer-timecard-system-for-salesforce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccb9a43d9f22aad88cb8e3471f91af83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kenji776</media:title>
		</media:content>
	</item>
		<item>
		<title>Salesforce Apex Prevent Record Editing/Saving after condition</title>
		<link>http://iwritecrappycode.wordpress.com/2012/01/19/salesforce-apex-prevent-record-editingsaving-after-condition/</link>
		<comments>http://iwritecrappycode.wordpress.com/2012/01/19/salesforce-apex-prevent-record-editingsaving-after-condition/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 15:33:50 +0000</pubDate>
		<dc:creator>kenji776</dc:creator>
				<category><![CDATA[Apex/Visual Force]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Edit]]></category>
		<category><![CDATA[Lock]]></category>
		<category><![CDATA[Prevent]]></category>
		<category><![CDATA[Record]]></category>
		<category><![CDATA[Salseforce]]></category>
		<category><![CDATA[save]]></category>

		<guid isPermaLink="false">http://iwritecrappycode.wordpress.com/?p=428</guid>
		<description><![CDATA[Hey all, this is just kind of a handy snippit. It will allow you to prevent a record from being edited if a condition on the record is met. This is nice for locking down a record as soon as some kind of field is set. Like say you have a status picklist that sends [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=428&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey all, this is just kind of a handy snippit. It will allow you to prevent a record from being edited if a condition on the record is met. This is nice for locking down a record as soon as some kind of field is set. Like say you have a status picklist that sends in a record for approval once it is in the stopped status and you want to make sure nobody modifies it, this will do that for you. This method is super dynamic. I can take maps of any kinds of sObjects, check any field for any value and return any error message you like. You would run this from a before update trigger. You pass the method the trigger.oldMap, trigger.newMap, the Id of the field that puts the record in the locked state, the value that field must have to be locked, and an error message to return. You would call it like this (provided you had saved the method in a class called utilities).</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">utilities.preventRecordEdit(Trigger.oldMap, Trigger.newMap, 'status__c', 'Stopped', 'Stopped timers may not be modified');
</pre>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">    public static void preventRecordEdit(map&lt;id,sObject&gt; oldObjects, map&lt;id,sObject&gt; newObjects, string controllingField, string lockingValue, string errorMessage)
    {
       //get the type of object this list is, like contact, account, etc
        Schema.sObjectType objectType = oldObjects.values().getSObjectType();

        //global describe of objects
        Map&lt;String, Schema.SObjectType&gt; globalDescribe = Schema.getGlobalDescribe(); 

        //describe object
        Schema.DescribeSObjectResult objectDescribe = objectType.getDescribe();

        //get all the valid fields on this object
        Map&lt;String, Schema.SobjectField&gt; objectFields = objectType.getDescribe().fields.getMap();

        for(sObject oldObject : oldObjects.values())
        {
            if(oldObject.get(controllingField) == lockingValue)
            {
                sObject newObject = newObjects.get((id) oldObject.get('id'));
                for(string fieldName : objectFields.keySet())
                {
                   if(oldObject.get(fieldName) != newObject.get(fieldName))
                   {
                       sObject actualRecord = (sObject) Trigger.newMap.get((id) oldObject.get('id'));
                       actualRecord.addError(errorMessage);
                   }
                }
            }
        }
    }
</pre>
<p>Not sure if there is an easier way, but if nothing else, it&#8217;s a cool tech demo for super dynamic Apex Code <img src='http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  Hope it helps someone.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iwritecrappycode.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iwritecrappycode.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iwritecrappycode.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iwritecrappycode.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iwritecrappycode.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iwritecrappycode.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iwritecrappycode.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iwritecrappycode.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iwritecrappycode.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iwritecrappycode.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iwritecrappycode.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iwritecrappycode.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iwritecrappycode.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iwritecrappycode.wordpress.com/428/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=428&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iwritecrappycode.wordpress.com/2012/01/19/salesforce-apex-prevent-record-editingsaving-after-condition/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccb9a43d9f22aad88cb8e3471f91af83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kenji776</media:title>
		</media:content>
	</item>
		<item>
		<title>Salesforce Custom Calendar with jQuery and Visualforce</title>
		<link>http://iwritecrappycode.wordpress.com/2012/01/18/salesforce-custom-calendar-with-jquery-and-visualforce/</link>
		<comments>http://iwritecrappycode.wordpress.com/2012/01/18/salesforce-custom-calendar-with-jquery-and-visualforce/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 18:01:05 +0000</pubDate>
		<dc:creator>kenji776</dc:creator>
				<category><![CDATA[Apex/Visual Force]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[apex]]></category>
		<category><![CDATA[Calendar]]></category>
		<category><![CDATA[fullcalendar]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[salesforce]]></category>
		<category><![CDATA[Visualforce]]></category>

		<guid isPermaLink="false">http://iwritecrappycode.wordpress.com/?p=418</guid>
		<description><![CDATA[Hey all, I know I&#8217;ve been promising a new calendar for a while, and I&#8217;m sorry it&#8217;s taken so long. I didn&#8217;t quite know how in depth I wanted to go, and how much stuff I should build. I finally just decided to release a nice simple framework for other developers to build on. This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=418&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey all,</p>
<p>I know I&#8217;ve been promising a new calendar for a while, and I&#8217;m sorry it&#8217;s taken so long. I didn&#8217;t quite know how in depth I wanted to go, and how much stuff I should build. I finally just decided to release a nice simple framework for other developers to build on. This is based on the super awesome excellent jQuery fullCalendar plugin by <a href="http://arshaw.com/fullcalendar/" title="jQuery fullCalendar" target="_blank">Adam Shaw</a>. What this allows you to do is create full calendar records (a custom object). Each record represents a calendar. Each calendar has a source object, a start and end field, and a list of detail fields. When the calendar is loaded, it then queries the specified object for all records with a start date and end date falling in the visible range of the calendar. When an event is clicked a popup box appears with further information that is configurable on the fullcalendar record. </p>
<div id="attachment_422" class="wp-caption aligncenter" style="width: 310px"><a href="http://iwritecrappycode.files.wordpress.com/2012/01/configshot.png"><img src="http://iwritecrappycode.files.wordpress.com/2012/01/configshot.png?w=300&#038;h=166" alt="" title="configShot" width="300" height="166" class="size-medium wp-image-422" /></a><p class="wp-caption-text">All the more configuration that is needed to create a calendar</p></div>
<p><div id="attachment_424" class="wp-caption aligncenter" style="width: 310px"><a href="http://iwritecrappycode.files.wordpress.com/2012/01/resultshot.png"><img src="http://iwritecrappycode.files.wordpress.com/2012/01/resultshot.png?w=300&#038;h=255" alt="" title="resultShot" width="300" height="255" class="size-medium wp-image-424" /></a><p class="wp-caption-text">Sample popup info when event is clicked</p></div><br />
<a href="http://xerointeractive-developer-edition.na9.force.com/partyForce/fullCalendar?id=a10E0000000Kzwv" title="Demo app" target="_blank">Click here for a demo</a> (go to December 2011 to see some sample events).</p>
<p>You can <a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04tE0000000PdDK" title="unmanaged package" target="_blank">grab the unmanaged package here</a></p>
<p>Or just <a href="http://www.box.com/s/q1hosqp5meec9rqc44qa" title="Grab the raw project source" target="_blank">grab the raw project and source from here</a> (first time hosting a file on box.net, we&#8217;ll see how this goes).</p>
<p>Anyway, I hope this helps some people who are looking for a simple calendar system, or one to build on. I&#8217;m happy to review suggestions and ideas, but I can&#8217;t commit to getting anything done. Hope ya dig it!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iwritecrappycode.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iwritecrappycode.wordpress.com/418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iwritecrappycode.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iwritecrappycode.wordpress.com/418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iwritecrappycode.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iwritecrappycode.wordpress.com/418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iwritecrappycode.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iwritecrappycode.wordpress.com/418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iwritecrappycode.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iwritecrappycode.wordpress.com/418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iwritecrappycode.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iwritecrappycode.wordpress.com/418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iwritecrappycode.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iwritecrappycode.wordpress.com/418/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=418&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iwritecrappycode.wordpress.com/2012/01/18/salesforce-custom-calendar-with-jquery-and-visualforce/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccb9a43d9f22aad88cb8e3471f91af83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kenji776</media:title>
		</media:content>

		<media:content url="http://iwritecrappycode.files.wordpress.com/2012/01/configshot.png?w=300" medium="image">
			<media:title type="html">configShot</media:title>
		</media:content>

		<media:content url="http://iwritecrappycode.files.wordpress.com/2012/01/resultshot.png?w=300" medium="image">
			<media:title type="html">resultShot</media:title>
		</media:content>
	</item>
		<item>
		<title>Salesforce, google maps, and jQuery fun</title>
		<link>http://iwritecrappycode.wordpress.com/2012/01/09/salesforce-google-maps-and-jquery-fun/</link>
		<comments>http://iwritecrappycode.wordpress.com/2012/01/09/salesforce-google-maps-and-jquery-fun/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 16:09:17 +0000</pubDate>
		<dc:creator>kenji776</dc:creator>
				<category><![CDATA[Apex/Visual Force]]></category>
		<category><![CDATA[CloudSpokes]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Salesforce]]></category>

		<guid isPermaLink="false">http://iwritecrappycode.wordpress.com/?p=416</guid>
		<description><![CDATA[Another Cloudspokes challenge entry submission. This one was for the challenge http://www.cloudspokes.com/challenges/1345. Basically the idea is get Sales data from Salesforce, plot it on a google map using geocoding without creating duplicate map points and allow a user to click one of the points to see all the sales data for it. The tricky part [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=416&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Another Cloudspokes challenge entry submission. This one was for the challenge <a href="http://www.cloudspokes.com/challenges/1345">http://www.cloudspokes.com/challenges/1345</a>. Basically the idea is get Sales data from Salesforce, plot it on a google map using geocoding without creating duplicate map points and allow a user to click one of the points to see all the sales data for it. The tricky part here is that the data comes from different objects based on what country you are filtering on (oh yeah, it has to support multiple countries). So data for the united states comes from a custom object called Sales Orders, while data for Japan and Germany come from opportunities. It had to allow to be easily expanded for more countries in the future as well with an easy way to set the data source. It was recommended to use address tools (an application from the app exchange that has prepopulated lists of countries and their states, along with some other data) for country and state data, but then there was some confusion because address tools is a for pay app with a 14 day trial. What is a developer to do? </p>
<p>I decided to try and make the best of both worlds. Using a flag in the javascript you can tell the controlling class whether to try and pull country and state data from address tools, or return a hard coded set of data (which was said to be an acceptable alternative in the comments of the challenge). The bummer here is that the org does at least have to have the address tools objects otherwise the class won&#8217;t compile. Nice thing is my installable package does include the objects and fields, so while it doesn&#8217;t have all the data that a full functionally addressTools would have it should at least install and not error. If you do have a functional addressTools install then no need to worry at all. The application will just work, because it defaults to attempting to pull it&#8217;s data from there.</p>
<p>To solve the issue of pulling data from different objects with different field names, I decided to create a wrapper object. A simple class that contains only the data needed to plot the address on the map. So whether the data be originally coming from Sales Orders or opportunities, they both end up returning a list of salesData objects (which is what I ended up calling my wrapper class). I created two separate methods (though they probably could have been consolidated into one, but it would have been a bit messy) for getting data from either object. The correct method was called by another which gets invoked by the user interface. Something like</p>
<p>User picks country<br />
Javascript uses apex remoting to call getSales(string formData);<br />
deserialize the form data from a url query string into a map of string to string (key to value)<br />
find useOpp key in the deserialized data (this got set by the javascript in the application before the request was sent)<br />
call the buildQueryFilter method and pass the form data. This method evaluates the data passed in the form and creates a SOQL where condition that will filter the records as the user has requested.<br />
If useOpp is true call the getOpportunitySales() method. If not, call the getSalesOrderSales() method.<br />
Both methods return a map of address (string) to salesData objects, using the filter created above.<br />
Return the map of addresses to salesData objects to the javascript to be plotted on the map.</p>
<p>Those few parts where really the trickiest part of this challenge. I feel creating the wrapper object was probably the slickest solution, and even allows for other potential data sources in the future, and easily expand-ability to return more data to the front end if desired. I&#8217;ll be honest and stay a little bit of my code is redundant because of a feature I added at the very last moment, so I end up deserializing the form data twice, which I should really only need to do once, but it&#8217;s a short string of data so it&#8217;s not a big deal. I also not 100% sure the application is safe from SOQL injection. You could probably get the application to error by passing junk data with firebug or something, but I doubt you could make it do anything besides just error. I mean SOQL is select only anyway, and the filters it runs through and the way the query string gets built is pretty solid. So I am pretty sure at worst an attack could just get the application to toss some errors for their instance of it. Nothing that should be able to bring the app down, especially with governor limits in place.</p>
<p>As usual, I can&#8217;t release the source code myself until I have lost, or Cloudspokes gives me the okay. They generally host all code on their github anyway so in that case I&#8217;ll updated this post with the link to it.</p>
<p>Anyway you can see the video here: <a href="http://www.screencast.com/t/cLUc7dqpHEkC" target="_blank">http://www.screencast.com/t/cLUc7dqpHEkC</a><br />
Or play with the <a href="http://xerointeractive-developer-edition.na9.force.com/partyForce/salesMap" title="Demo application" target="_blank">Demo App!</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iwritecrappycode.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iwritecrappycode.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iwritecrappycode.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iwritecrappycode.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iwritecrappycode.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iwritecrappycode.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iwritecrappycode.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iwritecrappycode.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iwritecrappycode.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iwritecrappycode.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iwritecrappycode.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iwritecrappycode.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iwritecrappycode.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iwritecrappycode.wordpress.com/416/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=416&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iwritecrappycode.wordpress.com/2012/01/09/salesforce-google-maps-and-jquery-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccb9a43d9f22aad88cb8e3471f91af83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kenji776</media:title>
		</media:content>
	</item>
		<item>
		<title>Salesforce Siteforce user configurable ajax links</title>
		<link>http://iwritecrappycode.wordpress.com/2012/01/04/salesforce-siteforce-user-configurable-ajax-links/</link>
		<comments>http://iwritecrappycode.wordpress.com/2012/01/04/salesforce-siteforce-user-configurable-ajax-links/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 16:50:44 +0000</pubDate>
		<dc:creator>kenji776</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[SiteForce]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[siteforce]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://iwritecrappycode.wordpress.com/?p=412</guid>
		<description><![CDATA[So I&#8217;ve been doing a big project recently, using the new Salesforce siteforce builder. For those who are unaware siteforce is basically a content management tool that allows regular non developer users to develop and manage websites, in theory anyway. Of course any website of significant complexity/usefulness is going to require a developer to at [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=412&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been doing a big project recently, using the new Salesforce siteforce builder. For those who are unaware siteforce is basically a content management tool that allows regular non developer users to develop and manage websites, in theory anyway. Of course any website of significant complexity/usefulness is going to require a developer to at least make some CSS and get some templates in place for the end user. One of the biggest things the users would do is edit content and links. Always with the updating of links, I tell ya. Problem is siteforce links are all just regular HREF links. In this ajax powered age, who wants that? I mean we want fast loading, partial page reloads, ajax baby! So how do I let a non coding user create ajax links to fetch the content and inject it into the page? Simple, you let them make links as normal, and use some javascript to modify them. </p>
<p>1) User creates standard HREF link with HREF pointing to desired page.<br />
2) Have some javascript modify the links at runtime to remove the HREF attribute, and replace with an onclick function<br />
3) onclick function fetches the content that was found in the original HREF and injects it into the page where desired.</p>
<p>My implementation of this idea looks like this.</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){

      $('.ajaxLink').each(function(index) {
        var linkTarget = $(this).attr('href');
        $(this).attr('href','#')
        $(this).click(function(){
            loadContent(linkTarget,'news_content');
            return false;
        });
    });    

    jQuery.ajaxSetup({
      beforeSend: function() {
         $('#loadingDiv').show()
      },
      complete: function(){
         $('#loadingDiv').hide()
      },

      error: function() { alert('Error loading page');},
      success: function() {}
    });

});

function loadContent(contentPath,contentTarget)
{

    console.log(contentPath + ' ' + contentTarget);
    $.get(contentPath, function(data)
    {
        $('#'+contentTarget).fadeOut('fast',function(){
            $(&quot;#&quot;+contentTarget).html(data);

            $(&quot;#&quot;+contentTarget).fadeIn()
        })
    })
}
&lt;/script&gt;
</pre>
<p>and the HTML</p>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">            &lt;style&gt;
                #news_picker
                {
                    width:20%;
                    height:100%;
                    overflow:auto;
                    float:left;
                }

                #news_details
                {
                    width:79%;
                    height:100%;
                    overflow:auto;
                    float:left;
                }
                #loadingDiv
                {
                    background-image:url(ajaxLoader.gif);
                    background-repeat:no-repeat;
                    background-position:center;
                    z-index:150;
                    display:none;
                }
            &lt;/style&gt;

            &lt;div id=&quot;news_picker&quot;&gt;
                &lt;div class=&quot;listHeader&quot;&gt;All of our news&lt;/div&gt;

                &lt;a href=&quot;news1.html&quot; class=&quot;ajaxLink&quot; &gt;Ajax link override&lt;/a&gt;

            &lt;/div&gt;

            &lt;div id=&quot;news_details&quot;&gt;
                &lt;div id=&quot;loadingDiv&quot;&gt;Content Loading, Please Wait.&lt;/div&gt;

                &lt;div id=&quot;news_content&quot;&gt; I am news data&lt;/div&gt;

            &lt;/div&gt;
</pre>
<p>this will transform any link with a class of &#8216;ajaxLink&#8217; and convert it from a regular link into an ajax loading link. Right now it is coded to push the fetched content into a div called &#8216;news_content&#8217; (you could make this dynamic, or even per link by including some attribute in the link itself that tells the function where to put the fetched content). You may want to add special case handling for content other than text/html, such as detecting if the requested resource is an image, and wrap it in an img tag, etc. Anyway, hope this helps someone, I thought it was pretty cool to allow users to easily create Ajax links <img src='http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iwritecrappycode.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iwritecrappycode.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iwritecrappycode.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iwritecrappycode.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iwritecrappycode.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iwritecrappycode.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iwritecrappycode.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iwritecrappycode.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iwritecrappycode.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iwritecrappycode.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iwritecrappycode.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iwritecrappycode.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iwritecrappycode.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iwritecrappycode.wordpress.com/412/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=412&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iwritecrappycode.wordpress.com/2012/01/04/salesforce-siteforce-user-configurable-ajax-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccb9a43d9f22aad88cb8e3471f91af83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kenji776</media:title>
		</media:content>
	</item>
		<item>
		<title>Salesforce jQuery Calendar</title>
		<link>http://iwritecrappycode.wordpress.com/2011/12/13/salesforce-jquery-calendar/</link>
		<comments>http://iwritecrappycode.wordpress.com/2011/12/13/salesforce-jquery-calendar/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 22:38:52 +0000</pubDate>
		<dc:creator>kenji776</dc:creator>
				<category><![CDATA[Apex/Visual Force]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Visualforce]]></category>
		<category><![CDATA[apex]]></category>
		<category><![CDATA[Calendar]]></category>
		<category><![CDATA[fullcalendar]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[salesforce]]></category>

		<guid isPermaLink="false">http://iwritecrappycode.wordpress.com/?p=409</guid>
		<description><![CDATA[Over the last year there has been a lot of people excited about my Salesforce jQuery calendar. Problem is, for one the code isn&#8217;t available due to a lack of hosting. Problem two is that it sucks. It uses some goofy visualforce page to pass information off the the apex class, and it can only [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=409&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Over the last year there has been a lot of people excited about my Salesforce jQuery calendar. Problem is, for one the code isn&#8217;t available due to a lack of hosting. Problem two is that it sucks. It uses some goofy visualforce page to pass information off the the apex class, and it can only query against one type of object. Overall, it&#8217;s pretty lame and not a good sample of the kind of work that is possible these days. So I am rebuilding it. In fact, I already have the core up and running. But now I want to know what kind of features you guys are interested in. Do you want a super bare bones easy to understand release, or do we want a little more robust full featured kind of thing? Let me know in the comments what you&#8217;d like to see in a new Salesforce calendar, and I&#8217;ll see what I can do.</p>
<p>For those who just want my basic functional super skeletal framework I&#8217;ll be releasing it sometime tomorrow. I need to clean up a few little things, and I&#8217;ll probably release it as an unmanaged package for easy install, and I&#8217;ll host the code on my new box.net account.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iwritecrappycode.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iwritecrappycode.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iwritecrappycode.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iwritecrappycode.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iwritecrappycode.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iwritecrappycode.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iwritecrappycode.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iwritecrappycode.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iwritecrappycode.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iwritecrappycode.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iwritecrappycode.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iwritecrappycode.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iwritecrappycode.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iwritecrappycode.wordpress.com/409/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=409&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iwritecrappycode.wordpress.com/2011/12/13/salesforce-jquery-calendar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccb9a43d9f22aad88cb8e3471f91af83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kenji776</media:title>
		</media:content>
	</item>
		<item>
		<title>Salesforce Apex CSV Parsing to sObject</title>
		<link>http://iwritecrappycode.wordpress.com/2011/12/01/salesforce-apex-csv-parsing-to-sobject/</link>
		<comments>http://iwritecrappycode.wordpress.com/2011/12/01/salesforce-apex-csv-parsing-to-sobject/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 17:25:09 +0000</pubDate>
		<dc:creator>kenji776</dc:creator>
				<category><![CDATA[Apex/Visual Force]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[apex]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[Import]]></category>

		<guid isPermaLink="false">http://iwritecrappycode.wordpress.com/?p=402</guid>
		<description><![CDATA[So for a recent project I&#8217;ve been working on, a person wants to be able to email in a small CSV file to an automated bot. The bot will extract the attachment, iterate through the data and import the data. So of course first I had to get together a CSV parser. Thankfully that was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=402&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So for a recent project I&#8217;ve been working on, a person wants to be able to email in a small CSV file to an automated bot. The bot will extract the attachment, iterate through the data and import the data. So of course first I had to get together a CSV parser. Thankfully that was already handled by the awesome people over at the developer force wiki. So first, grab their <a href="http://wiki.developerforce.com/page/Code_Samples#Parse_a_CSV_with_APEX">Apex CSV parser</a>.  So that returns a list of a list of strings. Each list entry is a list of the values in that row. So now while this is nice, it&#8217;s still not idea for importing. You need to convert that data into an sObject, or a list of them. So I drafted this little function that works in tandem with the first one. You can pass it that data you get from the first parser, and the type of sObject you want to serialize the data into and it will give you back a list of sObjects. Some things to note about this function.</p>
<ul>
<li>You must pass in the column headers as the first row</li>
<li>The column headers must match the API names of the fields. So your column headers must match the sObject field names</li>
<li>The parser can deal with invalid field names. It will simple not set them on the sObject. So you can include extra data, it will just be discarded</li>
<li>I havn&#8217;t tested it much. It may fail with some data types, but I&#8217;m not sure</li>
</ul>
<pre style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;color:#000000;background-color:#eee;font-size:12px;border:1px dashed #999999;line-height:14px;overflow:auto;width:100%;padding:5px;">    public static list&lt;sObject&gt; csvTosObject(List&lt;List&lt;String&gt;&gt; parsedCSV, string objectType)
    {
        Schema.sObjectType objectDef = Schema.getGlobalDescribe().get(objectType).getDescribe().getSObjectType();
        system.debug(objectDef);

        list&lt;sObject&gt; objects = new list&lt;sObject&gt;();
        list&lt;string&gt; headers = new list&lt;string&gt;();

        for(list&lt;string&gt; row : parsedCSV)
        {
            for(string col : row)
            {
                headers.add(col);
            }
            break;
        }
        system.debug('========================= File Column Headers');
        system.debug(headers);

        integer rowNumber = 0;
        for(list&lt;string&gt; row : parsedCSV)
        {
            system.debug('========================= Row Index' + rowNumber);
            if(rowNumber == 0)
            {
                rowNumber++;
                continue;
            }
            else
            {
                sObject thisObj = objectDef.newSobject();
                integer colIndex = 0;
                for(string col : row)
                {
                    string headerName = headers[colIndex].trim();
                    system.debug('========================= Column Name ' + headerName);
                    if(headerName.length() &gt; 0)
                    {
                        try
                        {
                            thisObj.put(headerName,col.trim());
                        }
                        catch(exception e)
                        {
                            system.debug('============== Invalid field specified in header ' + headerName);
                        }
                        colIndex++;
                    }
                }
                objects.add(thisObj);
                rowNumber++;
            }
        }
        return objects;
    }
</pre>
<p>If nothing else this should at least be a jumping off spot for anyone trying to work with CSV files in Apex. If you make any improvements, I&#8217;d love to see/hear them. Hope this helps someone!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iwritecrappycode.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iwritecrappycode.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iwritecrappycode.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iwritecrappycode.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iwritecrappycode.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iwritecrappycode.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iwritecrappycode.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iwritecrappycode.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iwritecrappycode.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iwritecrappycode.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iwritecrappycode.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iwritecrappycode.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iwritecrappycode.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iwritecrappycode.wordpress.com/402/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=402&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iwritecrappycode.wordpress.com/2011/12/01/salesforce-apex-csv-parsing-to-sobject/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccb9a43d9f22aad88cb8e3471f91af83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kenji776</media:title>
		</media:content>
	</item>
		<item>
		<title>CloudVote emerges as Appirio Social Enterprise Toolkit</title>
		<link>http://iwritecrappycode.wordpress.com/2011/11/30/cloudvote-emerges-as-appirio-social-enterprise-toolkit/</link>
		<comments>http://iwritecrappycode.wordpress.com/2011/11/30/cloudvote-emerges-as-appirio-social-enterprise-toolkit/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 15:53:03 +0000</pubDate>
		<dc:creator>kenji776</dc:creator>
				<category><![CDATA[CloudSpokes]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Appirio]]></category>
		<category><![CDATA[cloudspokes]]></category>
		<category><![CDATA[cloudvote]]></category>
		<category><![CDATA[Enterprise]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Open]]></category>
		<category><![CDATA[Social]]></category>
		<category><![CDATA[Toolkit]]></category>

		<guid isPermaLink="false">http://iwritecrappycode.wordpress.com/?p=399</guid>
		<description><![CDATA[Today is a bit of a proud moment for me. My entry for the CloudSpkes contest Social Enterprise Toolkit Ideas App has graduated and been deployed for use by the public. Marketwatch a nice little write did a up on the application. I&#8217;ve been helping the Appirio team make the last required tweaks, as well [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=399&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today is a bit of a proud moment for me. My entry for the CloudSpkes contest <a href="http://www.cloudspokes.com/challenge_detail.html?contestID=334">Social Enterprise Toolkit Ideas App</a> has graduated and been deployed for use by the public. Marketwatch a nice little write</a> did a  up on the application. I&#8217;ve been helping the Appirio team make the last required tweaks, as well as overhaul the design for the last few days (their graphic design team is quite awesome) and it looks like it is now live. You can check it out <a href="http://m.socialenterprisetoolkit.com">http://m.socialenterprisetoolkit.com</a>. It&#8217;s pretty cool to see my work move from concept, to beta, to production in a span of like 3 weeks. Although most will never know who wrote it, and won&#8217;t care I&#8217;ll at least now, and that&#8217;s good enough for me <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iwritecrappycode.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iwritecrappycode.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iwritecrappycode.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iwritecrappycode.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iwritecrappycode.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iwritecrappycode.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iwritecrappycode.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iwritecrappycode.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iwritecrappycode.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iwritecrappycode.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iwritecrappycode.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iwritecrappycode.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iwritecrappycode.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iwritecrappycode.wordpress.com/399/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=399&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iwritecrappycode.wordpress.com/2011/11/30/cloudvote-emerges-as-appirio-social-enterprise-toolkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccb9a43d9f22aad88cb8e3471f91af83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kenji776</media:title>
		</media:content>
	</item>
		<item>
		<title>Cloudspokes Challenge jQuery Clone and Configure Records</title>
		<link>http://iwritecrappycode.wordpress.com/2011/11/21/cloudspokes-challenge-jquery-clone-and-configure-records/</link>
		<comments>http://iwritecrappycode.wordpress.com/2011/11/21/cloudspokes-challenge-jquery-clone-and-configure-records/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 15:34:43 +0000</pubDate>
		<dc:creator>kenji776</dc:creator>
				<category><![CDATA[Apex/Visual Force]]></category>
		<category><![CDATA[CloudSpokes]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apex]]></category>
		<category><![CDATA[clone]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[salesforce]]></category>
		<category><![CDATA[Visualforce]]></category>

		<guid isPermaLink="false">http://iwritecrappycode.wordpress.com/?p=394</guid>
		<description><![CDATA[Hey everyone, Just wrapped up another CloudSpokes contest entry. This one was the clone and configure records (with jQuery) challenge. The idea was to allow a user to copy a record that had many child records attached, then allow the user to easily change which child records where related via a drag and drop interface. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=394&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey everyone,<br />
Just wrapped up another CloudSpokes contest entry. This one was the clone and configure records (with jQuery) challenge. The idea was to allow a user to copy a record that had many child records attached, then allow the user to easily change which child records where related via a drag and drop interface. I have a bit of jQuery background so I figured I&#8217;d give this a whack. The final result I think was pretty good. I&#8217;d like to have been able to display more information about the child records, but the plugin i used was a wrapper for a select list so the only data available was the label. Had I had more time I maybe could have hacked the plugin some to get extra data, or maybe even written my own, but drag and drop is a bit of a complicated thing (though really not too bad with jQuery) so I had to use what I could get in the time available. Anyway, you can see the entry below.</p>
<p><a href='http://www.screencast.com/t/Jh3hPHjpvYz'>jQuery Clone and Configure Record</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iwritecrappycode.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iwritecrappycode.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iwritecrappycode.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iwritecrappycode.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iwritecrappycode.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iwritecrappycode.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iwritecrappycode.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iwritecrappycode.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iwritecrappycode.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iwritecrappycode.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iwritecrappycode.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iwritecrappycode.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iwritecrappycode.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iwritecrappycode.wordpress.com/394/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iwritecrappycode.wordpress.com&amp;blog=10849749&amp;post=394&amp;subd=iwritecrappycode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iwritecrappycode.wordpress.com/2011/11/21/cloudspokes-challenge-jquery-clone-and-configure-records/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccb9a43d9f22aad88cb8e3471f91af83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kenji776</media:title>
		</media:content>
	</item>
	</channel>
</rss>
