Friday, March 18, 2011

Loading animation on Visualforce

Maybe its just be but even if you build the most amazing system in the world, it won't be awesome if it is not visually pleasing or beautiful UI. No font should not be uneven, or the images should not haywire. Everything should be in order. Perfect.

A simple script can save you a long email, informing you that a million dollar system is broken because it does nothing when users click the buttons. If you have a long processing happening in the background, its not good to assume your users are psych to know whats happening in background (if only we could see data packets send one by one).  If you do not show them that something is happening, they will end up clicking the button again and again, sending multiple request to the server. Worst case scenario your system will be returned back with a thank you note that excel sheet was better, this is broken. Have no fear, I am here.

If you have been following this blog for some time, I hope you do, you will know that 'Please wait' animation was one of the early scripts I published on this blog. The code was big, large and complex, maybe my understanding of VF was a little less back them (it was way back in 2009) or maybe my understand of VF is much better now, I found a optimized and simple way of doing it and using it on my projects.

<apex:actionstatus id="pleasewait">
    <apex:facet name="start">
        <img src="{!$Resource.AjaxAnimation}" />
    </apex:facet>
</apex:actionstatus>


The please wait image should be loaded in static resources with name 'AjaxAnimation'. You can download some nice images I collected for my own projects. This simple code will help you prevent that unpleasant email on a Monday morning that will spoil the whole day.

The best way to do it is make a custom component and keep it handy on all the pages, just add the component to the page. Working on a generic pagination component next, download and add and you have pagination for yourself.

Update: Thanks to Tim Inman, found an amazing site which gives you different Ajax Load images in different background and colors. Do visit http://ajaxload.info/
Share:

Wednesday, March 16, 2011

Social Landslide

We all live in a social world, where everyone knows someone, somewhere. A few days ago I wanted to determine the exact followers of my blog and the numbers were vast, I had around 150+ followers using google reader, 300 around using facebook and 450 around on twitter. Most of these followers overlapped each other. feedburner told me, amidst this chaos the total reach of my blog is 200 people per day on an average. So basically there was no way to determine the exact number of followers.

This actually got me thinking about the social scenario nowadays. An average person has joined more than one social network. The social scenario nowadays is completely cluttered and decentralized. We have many tools for the trade, while facebook connects me to my friends, flickr helps me share my albums. A colleague in office casually passed around a information, 'Did you add me on orkut? I uploaded some pictures on my Singapore trip on it.'

It was chaos, for I am already added on his Facebook, Gtalk and Twitter. The decentralization and competition between social vendors is creating massive amount of (in web lingo) spam. Sorting through this spam not only takes a toll but also gives you a heavy headache at the end of the day. And as it happened during the olden yahoo mail days, when the amount of spam is more than the amount of email in your inbox, you will miss out the important communication.

Michael Arrington from techcrunch says that just like Google pageRank did to online search, separation of crap from search results, someone should come up with something to help us sort through this mess of social landslide.
There are already tools for the trade available in form of tweet deck, seismic web and other tools etc.

There was a much hype many days ago about a flock social browser build on firefox by some Indian Cos. The concept was nice, where it gives the tools to keep things open even while browsing, but many people will agree with me that it also increases chunk. These tools give you simplified access to the vast social media but at the same time annoy us to the core by giving constant updates from all the networks.

We need something to actually categorize this vast chuck of data spreading like the virus and rank them for us. We need something to actually make sense of this large data and categorize it for us. Android mobiles comes inbuilt with social hub, a utility that connects all the online profiles of the friends into a single, streamlined interface for easy access.

There should be a social hub for the web that connects all the things together in a single streamline interface that is not only easy to operate but also easy to connect.

True Story.
Share:

Monday, March 14, 2011

Dynamic Approval Process on Salesforce

Ever come across the need of a large approval process where you do not know who the approver of the next stage will be? We all do don't we?

In a recent project requirement, I had to work on a big approval process. My basic requirement was:

1. One approval process for child object
2. Once child is approved, it should trigger the master object approval process

Both the approval process had around 5 steps and the approvers where determined by the role hierarchy and the region of the submitter.

Yikes is it?

Pre-requisites:
For this recipe, you need
1. Basic knowledge of APEX and trigger
2. Basic knowledge of Approval process
3. Aspirin (just in case you miss a step and have to debug it!!!)

So lets begin with the Child Object Dynamic Approval process.

Steps for Child Object Dynamic Process
1. Create two fields on the child object. These fields will not be shown on Page Layout.
       i) Approval_step__c: Text field to determine which step the approval is.
       ii) Next_approval__c: A user field to store the approver.

2. Create the approval process.
    i) Initial submission action will be field update: Approval_step__c='Submitted for approval'
    ii) In approver step, select related user and add the Next_approval__c
    iii) In the approval Step Action, field update for Approval_step__c with the next step of Approval. Keep a            note of these keywords.
   iv) Repeat the ii) and iii) till you finish all the approval steps.

3. Write a before update trigger on child object
   i) Check if Trigger.old.Approval_step__c != Trigger.new.Approval_step__c (this is a pseudo code, you will have to iterate through trigger.new and old and compare all values, if you do not know how to do this, add a comment below)
   ii) Now based on the value in Approval_step__c fetch the respective user from Role Hierarchy or anywhere else. Better option would be to use custom settings for this. Add this user in Next_approval__c
   iii) Repeat step ii) till you finish all the approval steps. The final approval step would be to either empty the  Next_approval__c field or set it back to manager of the user.


4. Optional step If you need to trigger another approval process after this.
   i) In the approval process, set the final approval action to 'Approved'
   ii) In the trigger if the field value is 'Approved' then submit the Master in Approval process using Apex Code. (There are many links which give you direct code, the code on my blog will come in next post. )

That's it. It is easily understood that you need to repeat the whole process for master if he needs dynamic approval.
After you done everything, take a deep breath and test your code. If it doesn't the way it should, take an aspirin and debug. Since this uses hand-shake between trigger and approval steps make sure you don't miss out on any step.

It works and I did not need Aspirin, thank God for that.

Note: As this approval process updates back-end, the visual process manager won't be able to visualize it.

Hope it helps,

Share: