Saturday, May 18, 2013


Few days back I came across a requirement which where user needed a scheduled job, that invokes after x days of record creation and creates a clone record.

So my initial thought was Scheduled Apex job but that doesn't seem to fit for this case because of the limit on number of scheduled jobs that can be scheduled. So started thinking of another approach and solution was pretty simple

WorkFlow Time Trigger + Apex Trigger = Invoke Apex @ Future Date.

Wasn't the equation clear enough? 
Well let me explain the same in steps.

  • Define Workflow
    • Create a new workflow 
      • Specify a entry criteria that fits your requirement. In my case it needs to go inside the  workflow as soon as it is created. So I just used formula editor and entered formula as "TRUE" as Rule Criteria and Evaluation Criteria as "Created". 
    • Add Time Trigger
      • Add time trigger to the apex and provide appropriate time duration. In my case I chose 30 days from "Rule Trigger Date"(Which will be same as created date). 
    • Add a field Update to the time trigger
      • Now add a field update that will be used by Apex Trigger to execute a class. So In my case the custom object had a custom field with the name "invokeApex__c" which was by default set to "FALSE".
      • Create a field update that will set this to "TRUE"

Well now you are done with the configuration part. Lets write some code
  • Creating a APEX Trigger.
    • Sample trigger will look like
       trigger invokeApexCloning on Demo__c (after update__c) {  
         for(Demo__c demo : trigger.New){  
           if(demo.invokeApex__c != trigger.Old.get(demo.Id).invokeApex__c && demo.invokeApex__c == TRUE){  
             //invoke your action here  
             CloningUtil.clone(demo);  
           }  
         }  
       }  
      
       
    • Modified version if you want to bulkify the same
       trigger invokeApexCloning on Demo__c (after update__c) {  
         List<Demo__c> demoList = new List<Demo__c>();  
         for(Demo__c demo : trigger.New){  
           if(demo.invokeApex__c != trigger.Old.get(demo.Id).invokeApex__c && demo.invokeApex__c == TRUE){  
             demoList.add(demo);  
           }  
         }  
         //invoke bulk action from here  
         CloningUtil.clone(demoList);  
       }  
      
Well thats all we are set now. This code setup will let you clone the records after 30 days. Now you know the secret to mix Time Triggers with Apex Triggers ;)

Thursday, May 9, 2013


[Live Demo]

This is another blog regarding so called Easy Jquery Component.Now this component helps you to generate  the Jquery Tabs very easily in a Visualforce pages. Follows the same syntax as the standard component, with added Jquery goodness. Pretty straight forward and can include standard components inside the Jquery tabs.

How it looks like ?



How to use the components?

  • <c:Tabpanel> : A wrapper component that holds all the tab together inside a panel.
  • <c:Tab> : Represents a single Tab inside a tabpanel.
Below is a sample code to generate a Jquery Tab

<!--Tab Panel -->  
   <c:Tabpanel >  
     <!--First Tab-->  
     <c:Tab title="Tab 1">  
       This is a tab 1. You can add standard component inside also.  
       <apex:pageBlock title="Standard page block">  
         This is a pageblock component.  
         <br/>  
         <apex:pageBlockSection title="This is a section" collapsible="false">  
         </apex:pageBlockSection>  
       </apex:pageBlock>  
     </c:Tab>  
     <!--Second Tab -->  
     <c:Tab title="Tab 2">  
       This is a tab 2  
     </c:Tab>  
   </c:Tabpanel>  

Codebase