For SFDC Admins : To do Dashboard Auto Refresh in Salesforce

Auto refreshing dashboard:

This is the feature many SFDC Admins have been asking for. Currently it is not possible to refresh the dashboard automatically when the sfdc user logs in to

Use the following steps to refresh the dashboard( automatically…after 5 seconds) when the user logs in to the salesforce OR the user clicks the home tab:-¬†

1) Create a new custom Home Page Component( type:HTML)

2) Add the following code:-(click the show html button before pasting the code)

3) save and Add this component to your Home Page Layout.

quite simple….right?? ūüôā

Object sharing using Email approval in Salesforce

This solution gives record access to a Salesforce user via email approval. Here we are providing access to the Accounts but this can be generalized for any standard or custom object.
 In order to grant access to the Account, an approval workflow request would be sent to the record owner and upon approval Apex code would be executed to add the requested user in the Account Team/Share objects.
1    1.    Provide a Request for Access button against each Account record on the Visual force page.
a.      Display a pop-up to the end user: A Request Email has been sent for Access.
b.¬†¬†¬†¬†¬† Create a Custom Object ‚ÄúAccount Sharing Request‚ÄĚ and add an Entry in this object:
AccountID, OwnerID, RequestedBy(UserID),IsApproved(False) for the request.
2.      Create an Approval process for Account Sharing Request in the controller class and send an approval request email to the record owner. 
3.      Enable email approval response so that the user can approve or reject the request by replying to the email: approve, approved, yes, reject, rejected,or no.
4.      Update IsApproved field to True upon approval: This is the Final approval action.
5.      Update trigger on the Account_Sharing_Request__c object would add the requested User to the Account Team and Account share Object.


How to create RowID in Tables : Here is the Code or Script Code for ID creation

If you are looking for to How to create RowID in Tables : Here is the Code or Script Code for ID creation,
Find below a simple Script or Code for generating Row ID or Record ID in Tables for Salesforce
public void viewTracking(){
if(trackingRow != null){
list rowId = trackingRow.split(‘:’);
if(rowId.size() >1){
//system.debug(‘***’+ integer.valueof(rowId[(rowId.size()-2)]));
Tracking =orderDetails[integer.valueof(rowId[(rowId.size()-2)])].Tracking;
Using RowID can be helpful in many ways to identify a record, count the records, classify, add, insert or delete a record or row just with a command in Tables.

Query User access Level in Apex

     With API 24 salesforce has given access to UserRecordAccess table. This gives us more power in querying whether user have access and upto what level so that we can build our VF and apex accordingly.

I was writing a VF page in which i needed to have a table of sobject records with Edit and del links for each line item. I was using{!URL for} function which would take care of the link automatically. It would even prevent users who do not have permission to edit or delete the record to take it to the page ‘you do not have sufficient permission’.

I thought it would be nice to know if the loggedin user or profile permission can be queried based on which i could display or hide these links instead of user clicking the link and finding out. Thats when i searched i figured it could be handled with Api 24.0

SELECT RecordId, HasReadAccess, HasTransferAccess, MaxAccessLevel
     FROM UserRecordAccess
     WHERE UserId = [single ID]
     AND RecordId = [single ID]      //or Record IN [list of IDs]

so i needed to get info on hasEditAccess and hasDeleteAccess for loggedin user and based on which i displayed or hid the link. It worked like charm.


How to Sort an Apex class Object List

[Edit : Now there is an interface natively provided by salesforce to sort the class object lists]

I recently needed to sort an apex class object List which was retrieved through a webservice callout as it could not be sorted at the service end.

This is the apex method which was used to build it

 public void testsort(){
map<string,List> stracc = new map<string,list>();
for(accClass a:accClassobj ){
stracc.put(,new accclass[]{a});
accclassobj= new list();
list nameList = new list();
for(string s:nameList){

Above is the code involved in sorting to build a map with object parameter as the key by which we gonna sort and List.


How to Filter list alphabetically

How to Filter list alphabetically

There was a requirement where i needed to build a list which can be filtered based on the starting alphabet. And also the List needs to remember the selections made as we move through other pages.


Please wait…

In the VF page i am displaying the List ‘CurrentLsit‘ which would hold the contact list with checkbox which is paginated and ‘DisplaySelectedList‘ which would remember the selected contact. Array Alphabet is used in repeat to build the link of alphabets at the top of page

Controller method

public with sharing class Pagin_alpha {    
    private List contactSetList{get;set;}
    private string contactListQuery;
    private set selectedContact;
    public List alphabet{get;set;}
    public boolean fals{get;set;}  
    public Pagin_alpha(){
¬†¬†¬†¬†¬† alphabet=new string[]{‘All’,’a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’ };¬†
      contactSetList = new List();
      selectedContact = new set();
¬†¬†¬†¬†¬† contactListQuery= ‘select id,name,phone from contact limit 1000’;¬†¬†¬†
     Private void updateSelectedContact(){
        for(contactSet cs:contactSetList ){
      public ApexPages.StandardSetController standardSetCon {
        get {
            if(standardSetCon == null) {
                standardSetCon = new ApexPages.StandardSetController(Database.getQueryLocator(contactListQuery));
                // sets the number of records in each page set
                standardSetCon .setPageSize(20);
            return standardSetCon ;
    public List getCurrentList() {
       contactSetList = new List();      
        for (contact category : (List)standardSetCon.getRecords()){       
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† contactSetList.add(new contactSet(category,’true’));
            contactSetList.add(new contactSet(category));
        return contactSetList;
    public PageReference refreshList2() {      
       standardSetCon = null;    
       string s;
¬†¬†¬†¬†¬†¬† if(apexpages.currentpage().getparameters().get(‘alpha’) == ‘All’)
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† s=’%’;
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† s= apexpages.currentpage().getparameters().get(‘alpha’)+’%’;
¬†¬†¬†¬†¬†¬† contactListQuery= ‘select id,name,phone from contact where name like’ +”’+s +”’+ ‘limit 5000’;¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†
        return null;
    public List getDisplaySelectedList(){
        List displaycon = new list();
        return displaycon;
    public class contactSet {
        public Boolean checked{ get; set; }
        public contact ocontact { get; set;}         public contactSet(){
            ocontact = new contact();
            checked = false;
        public contactSet(contact c){
            ocontact = c;
            checked = false;

        public contactSet(contact c,string s){
            ocontact = c;
            checked = true;


getCurrentList populates the currentList in the page. refreshList2 will refresh the list when the link on top of the page to filter the contact is clicked.

This concept can be extended to multiple fields in the List .


Hierarchy in VisualForce

Hierarchy in VisualForce is an interesting feature unique to VisualForce

This is an example of how to build a hierarchy Lists in VF page with select checkboxes. It will have a checkbox at parent level with which you can select all the child automatically. It has a neat link with which you can show or hide children under a parent row. It uses jquery libraries for achieving this. It has a list of accounts with each accounts displaying all its contacts in a hierarchy view.

Apex Class

public class accconhierarchy {
    Private list acc;
    public List accountList { get; set; }
    public accconhierarchy (){
        List cw;
        accountList = new List();
        acc = [select id,name,industry,billingcountry,createdbyid,(select id,name,email,phone from contacts) from account limit 20];
        for(account a:acc){
            cw = new list();
            For(contact co : a.contacts){
               cw.add(new contactWrap(co));
            accountList.add(new accountWrap(a,false,cw));
    public class accountWrap{
        public account oAccount{get;set;}
        public boolean isSelected{get;set;}
        public List contactset{get;set;}
        public accountWrap(account a,boolean b, List c){
            contactset =c;           
    public class contactWrap{
        public contact oContact{get;set;}
        public boolean isSelected{get;set;}       
        public contactWrap(contact a){

Visualforce Page



¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† rendered=”{!accountList.size!=0}”>



                                   Account Name


                                   Billing Country


¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† value=”{!accountList}”
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† var=”item”>


¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† value=”{!item.IsSelected}”
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† onclick=”javascript:toggleSelectAll(this, ‘{!$Component.repeatAccount}’);”/>




¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† value=”{!item.contactSet}”
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† var=”subitem”>


JS function toggleContactRow is used to show or hide contacts and toggleSelectAll is for header level checkbox at the parent Level.

SFDC API 24.0 test failure issue

Yesterday I was experiencing a weird issue. My SFDC API Test Failed.For a new requirement we did development in our DEV environment‚ĶWe wrote new test methods and we thought the work is done :)…
However, there were Null Pointer Exceptionswhen we ran the test methods.
And it was pointing to the custom settings….we doubled checked and confirmed that the custom setting had the default values. Also, it was accessible to anyone (public).

After some time I realized that the test method API version was 24.0.. I changed it to 23.0 and there were no errors ūüôā

Edit – SFDC has introduced test classes not to access data directly with API 24. Even though it is a good move , I would like to access certain info by default like custom settings, and Pricebook. But there is always an option to use @istest(seealldata=true) to access live data.

Batch scheduler class testing

Template for batch & scheduler class test method:@isTest 

private class Test_Nameofurclass {
    static testmethod void test_Nameofurclass (){
        DateTime currTime =;
        Integer min = currTime.minute();
        Integer hour = currTime.hour();
        String sch;
    if(min <= 58)
¬† ¬† ¬† ¬† ¬† ¬† sch = ‘0 ‘+ (min + 1) + ‘ ‘ + hour + ‘ * * ? ‘+ currTime.year();
¬† ¬† ¬† ¬† ¬† ¬† sch = ‘0 0 ‘+ (hour + 1) + ‘ * * ? ‘+ currTime.year();
    nameofschedularclass obj = new nameofschedularclass  ();
¬† ¬† String jobId = system.schedule(‘test’, sch, obj);
        CronTrigger ct = [SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger where id = :jobId];
        System.assertEquals(sch, ct.CronExpression);
        insert test records satisfying your query. 
        database.executeBatch(new nameofurbatchclass());