Tuesday, 12 August 2014

Dreaming Dreamforce 2014

Hi Folks,

This time I have clubbed my ideas in form of poem. Here it is:

Different minds come on common place
Where your problems will get replaced
with a solution standing in-front of you.
Solutions would surround to you.

Dreamforce forces you to one more Dream
It finds contribution of Dev Cream
It forces you to work hard
To let bring out your idea-train from yard

Dreamforce never sleeps
Elaborate whatever you keep
You will find many new ideas
You would fall in love of its areas.


Lets go to DF#14
Come to DF#14
Welcome to DF#14

Tuesday, 10 June 2014

Salesforce Record Accessibility Calculator

Hi Friends, Recently I got a situation where where I had to redirect to a record page where I have not access and got error message like :"Insufficient Privileges You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary." So I have implemented a calculator for record accessibility for any user. You just need to provide record id of S-object and user Id. It will calculate and will show complete access level.
Here Is Code snippet VF Code :

  
  
      
                        
              
                  Please Enter Record ID:    
                  
              
              
                  Please Enter User:    
                  
               
              
                  Note: IF you don't select user then record accesibility will be calculated for logged user 
                           
              
                  
                
          
          
          
          
          
              
                  
                  
                  
                  
                  
              
          
          
      
  

Apex Class Code :
Public Class AccessLevelCalculatorClass{

// Public Variables
Public String recordId{get;set;}
Public User U {get;set;}
Public Contact C {get;set;}
Public List URAs { get;set;}


// Constructor
Public AccessLevelCalculatorClass()
{   
    // Initialization
    U = new User();
    C = new Contact();
    URAs  = new List();
}

// Method to calculate access level
Public PageReference toCalculate()
{
    Try
    {   
        IF(recordId  == null || recordId  == '')
        {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Error, 'Please Enter Valid Record Id');
            ApexPages.addMessage(myMsg);
            return null;
        } 
        
        URAs  = [Select RecordID, HasreadAccess, HaseditAccess, HasdeleteAccess,HasTransferAccess ,HasAllAccess 
                       From UserRecordAccess where recordID=: recordId And UserId =: UserInfo.getUserId()];
        
        String UserId = C.Related_User__C ;
        If(C.Related_User__C == null)
        {
            UserId = UserInfo.getUserId();
        }
        
        for(User tempUser : [select Name from User Where id = : UserId  ])
        {
            U = tempUser; 
        }
        IF(URAs.size() == 0)
        {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.WARNING, 'Either Record Id is no correct or You do no have any access of this record');
            ApexPages.addMessage(myMsg);
            Return null;
        }
    }   
    Catch(Exception e)
    {
        ApexPages.Addmessages(e);
    }                
    return null;
}

}
Thanks for sharing your time with it.