Monday 24 June 2013

Page Views Counter widget in salesforce

Hi All,
Today, I am going to show you an application of cookies in context of salesforce. I think, at many discussion boards and blog areas you have seen number of page views or visitor counter on top of that if not you can see it on this current blog in right panel. So what I implemented is same counter widget in salesforce using cookies. Cookies is a API which helps you to let your browser remember many things which you don't want. So here I have composed it with in VF page, Apex class & to expose it I have used force.con site feature.




Please Click on below link to get Demo.
Demo Link

 Visualforce Page:

  
      
          You are visitor number : {!visitorNumber}
      
  

Apex Class:
public class PageviewCouterUtilClass {
    public String visitorNumber{get;private set;}
    public PageviewCouterUtilClass () {
        Cookie PageCounter = ApexPages.currentPage().getCookies().get('PageCounterCookie');
         
        // User is accessing page first time       
        if (PageCounter == null) {
            PageCounter = new Cookie('PageCounterCookie','1',null,-1,false);// create a new cookie 'PageCounterCookie', an initial value : '1', path :  'null', maxAge  : '-1'and isSecure : 'false'.
        } else {        
            Integer visitorNumber = Integer.valueOf(PageCounter.getValue());
            PageCounter = new Cookie('PageCounterCookie', String.valueOf(visitorNumber+1),null,-1,false);
        }    
        // Set the new cookie for the page
        ApexPages.currentPage().setCookies(new Cookie[]{PageCounter});  
        if(PageCounter == null) 
        {
            visitorNumber = '0';
        }   
        else
        {
            visitorNumber =  PageCounter.getValue();
        }     
    }
}

Here is a limitation of loosing counter in case of deleting cookies in this case counter will be reset. To avoid this problem you can store this counter value in your salesforce org like custom setting.

Thanks 
Sandeep

Sunday 9 June 2013

List of Components available in Change Set for Migration

Hi Friends, "Is it possible to migrate this component through Change Set or not?" such type of queries are ofently found in discussion & forums.To check this out we need to create sample change set(which is not possible in free Developer Org.) it takes time. So for answering all these queries at once I have listed here all components which are possible to migrate through change set in Salesforce as below :

Account Owner Sharing Rule Account Territory Sharing Rule Action
Analytic Snapshot Apex Class Apex Sharing Reason
Apex Trigger App Approval Process
Assignment Rule Auth. Provider AutoResponse Rule
Button or Link Call Center Campaign Criteria Based Sharing Rule
Campaign Owner Sharing Rule Case Criteria Based Sharing Rule Case Owner Sharing Rule
Contact Criteria Based Sharing Rule Contact Owner Sharing Rule Custom Data Type
Custom Field Custom Label Custom Object
Custom Object Criteria Based Sharing Rule Custom Object Owner Sharing Rule Custom Report Type
Custom Setting Dashboard Document
Email Template Escalation Rule External Data Source
Field Set Flow Folder
Group Home Page Component Home Page Layout
Language Translation Lead Criteria Based Sharing Rule Lead Owner Sharing Rule
Letterhead List View Opportunity Criteria Based Sharing Rule
Opportunity Owner Sharing Rule Page Layout Permission Set
Queue Record Type Remote Site
Report Role S-Control
Send Action Static Resource Tab
Territory Validation Rule Visualforce Component
Visualforce Page Workflow Email Alert Workflow Field Update
Workflow Outbound Message Workflow Rule Workflow Task
Zone

List is updated as per summer'13 Release. I will update this list in next salesforce releases.

Thursday 6 June 2013

How to fetch Standard Profiles from SOQL

Hi friends today I am going to share one small trick. 
Recently I met with a problem where I need to fetch only standard profiles in SOQL. I went to force.com developer board and some other discussion forums and finally found the work around.

As we all know that there is no such attribute on profile to determine whether it is standard or custom so we can use a concept here that "standard profile gets created along with organization by Salesforce only" so it's created Date time would be same as organization.


Datetime OrgCreatedDateTime = [Select id , createdDate from Orgaization ][0].CreatedDate ;



Now we would like to query profile with same createdDate time.

List<profile> StandardProfiles = new List<profile>();
StandardProfiles = [select id,Name from Profile where createdDate = :OrgCreatedDateTime];

So "StandardProfiles"  is list of all standard profile of our org this is just a work around because I am still worried if a new standard profile gets enabled on demand after creating Org.
Please share your views ahead.