<?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>jonathanrico. &#187; visualforce</title>
	<atom:link href="http://jonathanrm.com/tag/visualforce/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanrm.com</link>
	<description></description>
	<lastBuildDate>Sun, 01 Aug 2010 18:01:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<script type="text/javascript">

if (typeof Meebo == 'undefined') {

Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};
(function(q){

	var args = arguments;
	if (!document.body) { return setTimeout(function(){ args.callee.apply(this, args) }, 100); }
	var d=document, b=d.body, m=b.insertBefore(d.createElement('div'), b.firstChild); s=d.createElement('script');
	m.id='meebo'; m.style.display='none'; m.innerHTML='<iframe id="meebo-iframe"></iframe>';
	s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;
	b.insertBefore(s, b.firstChild);

})({network:'jonathanrico_jo56qo'});	}</script>	<item>
		<title>Force.com Apex Merge/Replace Class ;)</title>
		<link>http://jonathanrm.com/2010/02/force-com-apex-mergereplace-class/</link>
		<comments>http://jonathanrm.com/2010/02/force-com-apex-mergereplace-class/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 07:26:10 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[apex]]></category>
		<category><![CDATA[force.com]]></category>
		<category><![CDATA[visualforce]]></category>

		<guid isPermaLink="false">http://jonathanrm.com/?p=85</guid>
		<description><![CDATA[Hello again! I just developed an Apex class for performing replace/merge operations on any kind of object, and yes any kind of relations as well! , so it doesn&#8217;t matter if you have master-detail relationships that can&#8217;t be modified, objects tied in a master-detail relationship will be cloned, deleted and inserted with the new values [...]]]></description>
			<content:encoded><![CDATA[<p>Hello again!</p>
<p>I just developed an Apex class for performing replace/merge operations on any kind of object, and yes any kind of relations as well! , so it doesn&#8217;t matter if you have master-detail relationships that can&#8217;t be modified, objects tied in a master-detail relationship will be cloned, deleted and inserted with the new values to simulate a merge operation!</p>
<p>To use the Merge class  just create an ObjectMerge instance, passing as an argument of the constructor your current record:</p>
<p><strong>ObjectMerge oMerge = new ObjectMerge(SourceObject); </strong></p>
<p>And to peform the merge operation just use the replaceRecord method and thats it!, you can specify if you want to delete the source record after the merge operation is done.</p>
<p><strong>oMerge.replaceRecord(MergeToThisObjectID,DeleteSourceObject);</strong></p>
<p>You can limit the number of records that will be processed in the merge operation for Master-Detail relations  to avoid hitting governor limits. The ObjectMerge class will let you know if there are any objects left, and if this is the case just continue performing the merge operation.</p>
<p>Force.com provides a merge DML operation but it&#8217;s only available for some of their standard objects, this class can help you get around that.  There are still some limitations with this class due to governor limits in the number of describe calls but unless you have a large amount of objects related to the replaced/merged record it should work pretty well.</p>
<p>For now, the Object Merge class only merges/replaces custom objects related to your record, but this can be changed  in the class , however keep in mind that no more than 10 relations can be processed due to describe calls limitations so be careful when removing the custom objects limitation because there can be many Non-Custom objects related to your record.</p>
<p>I&#8217;ll leave a link in this post to the files but for now here&#8217;s an example of how to use the ObjectMerge class in a VisualForce controller that merges contacts, if you have custom objects tied a contact A and want to merge contact A to Contact B you will see how the ObjectMerge class changes all of the objects from contact A to contact B then deletes contact A. Remember, you can try it with any custom object <img src='http://jonathanrm.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   Enjoy!</p>
<p>Download the files from here &#8211;&gt; <a title="ObjectMerge Files" href="http://jonathanrm.com/wp-content/uploads/2010/02/ObjectMerge1.zip" target="_blank">ObjectMerge</a></p>
<p>(NOTE: There&#8217;s a bug with the code viewer plug-in, please ignore the second viewer)</p>
<img style='display:none' id="post-85-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://jonathanrm.com/2010/02/force-com-apex-mergereplace-class/',title:'Force.com Apex Merge/Replace Class ;)',tweet:'Hello again! I just developed an Apex class for performing replace/merge operations on any kind of o',description:'Hello again! I just developed an Apex class for performing replace/merge operations on any kind of o'})"><script type='text/javascript'>document.getElementById("post-85-blankimage").onload();</script><textarea cols="40" rows="10" name="code" class="Java">public class MergeController{
    
    //This is just an Aux Object to get a Lookup Field in the VisualForce Page
    public Contact MergeAux{get;set;}
    //Declare an instance of the Object Merge Class
    private ObjectMerge oMerge;
    //Save the current contact in the controller (optional)
    private final Contact currentContact;
        
    public MergeController(ApexPages.StandardController controller){

        //Initialize all of our objects
        currentContact = (Contact)controller.getRecord();    
        MergeAux =new Contact();
        oMerge = new ObjectMerge(currentContact);        
        
    }
    
    //Merge Action
    public PageReference doMerge(){

        try{
     
            //Run the merge operation!, you can specify a second argument to delete the record after merge or not
            oMerge.replaceRecord(MergeAux.ReportsToId,false);
            
            //Do corresponding actions if merge operation was successful
            if(oMerge.bAppliedReplace){
                PageReference ref = new PageReference('/'+MergeAux.ReportsToId);
                ref.setRedirect(true);
                return ref;
            }else{
                return null;


        }catch(Exception e){
            
            ApexPages.addMessages(e);
            return null;    
        }
        
    }   

}

//And the Visual Force page will look something like this:

<apex:page standardController="Contact" extensions="MergeController">
     
     <apex:form >
         <apex:pageBlock >
             <apex:pageMessages id="messages">
             </apex:pageMessages>
             
             <apex:pageBlockButtons >
                 <apex:commandButton value="Merge" action="{!doMerge}" rerender="messages"/>
             </apex:pageBlockButtons>
             <apex:pageBlockSection columns="1">
                 <apex:outputField value="{!Contact.Name}"/>
                 <apex:inputField value="{!MergeAux.ReportsToId}"/>                
                 
             </apex:pageBlockSection>
         </apex:pageBlock>
     </apex:form>
     
</apex:page>

</textarea>
	<!-- WordPress Code Snippet -->
	<script type="text/javascript" src="http://jonathanrm.com/wp-content/plugins/wordpress-code-snippet/js/shCore.js"></script><script type="text/javascript" src="http://jonathanrm.com/wp-content/plugins/wordpress-code-snippet/js/shBrushJava.js"></script>
	<link type="text/css" rel="stylesheet" href="http://jonathanrm.com/wp-content/plugins/wordpress-code-snippet/css/SyntaxHighlighter.css"/>
	
	<script language="javascript">
	dp.SyntaxHighlighter.ClipboardSwf = 'http://jonathanrm.com/wp-content/plugins/wordpress-code-snippet/js/clipboard.swf';
	dp.SyntaxHighlighter.HighlightAll('code');
	</script>
	<!-- End WordPress Code Snippet -->
	]]></content:encoded>
			<wfw:commentRss>http://jonathanrm.com/2010/02/force-com-apex-mergereplace-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autocomplete component</title>
		<link>http://jonathanrm.com/2009/04/autocomplete-component/</link>
		<comments>http://jonathanrm.com/2009/04/autocomplete-component/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 19:57:55 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[force.com]]></category>
		<category><![CDATA[visualforce]]></category>

		<guid isPermaLink="false">http://jonathanrm.com/?p=45</guid>
		<description><![CDATA[Hello everyone, just wanted to share with the community this custom component I made and give something back for the help I&#8217;ve received The purpose of the component is to enable autocomplete in lookup fields. I used the autocomplete js created by Jim Roos: (http://www.jimroos.com/2007/05/ajax-autocomplete.html) but made some modifications to it so that it could [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everyone, just wanted to share with the community this custom component I made and give something back for the help I&#8217;ve received <img src='http://jonathanrm.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The purpose of the component is to enable autocomplete in lookup fields. I used the autocomplete js created by Jim Roos:<br />
(http://www.jimroos.com/2007/05/ajax-autocomplete.html) but made some modifications to it so that it could interact with an Apex controller among some other things&#8230;</p>
<p>So my idea was that if you were making a VF page that had an inputfield that was related to a lookupfield you would just insert this autocomplete component to that inputfield.</p>
<p>Something like this:</p>
<p style="padding-left: 30px;">&lt;apex:inputField value=&#8221;{!Contact.accountid}&#8221; id=&#8221;accname&#8221; styleClass=&#8221;cField&#8221;&gt;</p>
<p style="padding-left: 30px;">&lt;c:autocomplete ObjectName=&#8221;Accounts&#8221; InputId=&#8221;{!$Component.accname}&#8221;</p>
<p style="padding-left: 30px;">AutoCompleteId=&#8221;accACid&#8221; ClassName=&#8221;autocomplete300&#8243;/&gt;</p>
<p style="padding-left: 30px;">&lt;/apex:inputField&gt;</p>
<p>The component has 4 parameters:</p>
<p>The name of the object or custom object that the inputfield relates to (new objects must be added inside the apex classes since i had some problems constructing a dynamic query).<br />
The InputId which is used to relate the component to the input field<br />
The id for the Component<br />
A classname parameter that basically just defines the width of the suggestions menu.</p>
<p>Here&#8217;s a screenshot of how it looks like in action:</p>
<p><img src="http://www.jonathanrm.com/files/accomponent1.gif" border="0" alt="" /><br />
<img src="http://www.jonathanrm.com/files/accomponent.gif" border="0" alt="" /></p>
<p>Here&#8217;s a link to the file containing the required files:<br />
<a href="http://www.jonathanrm.com/files/autocomplete.zip" target="_blank"><br />
AutoCompleteComponent</a></p>
<img style='display:none' id="post-45-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://jonathanrm.com/2009/04/autocomplete-component/',title:'Autocomplete component',tweet:'Hello everyone, just wanted to share with the community this custom component I made and give someth',description:'Hello everyone, just wanted to share with the community this custom component I made and give someth'})"><script type='text/javascript'>document.getElementById("post-45-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://jonathanrm.com/2009/04/autocomplete-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
