Monday 8 December 2014

How to refer custom html page from document in visualforce page.

Hi All, 

I came across one requirement during work, thought to share, it will be useful info for you. I was working on designing partner portal site for user,as you all know for designing site,we have to take care of company branding, header and footer and lot more style sheet and css, and it's not a best practice to use all the code in vf page itself ,because same header and footer might be required to be used in several pages,so it's better we will keep it separately whenever it is required we can refer it.

We have stored header and footer code(html page with css) in document object in sfdc.Now the question is how can we refer it in vf page? If we have stored in static resource it is quite simple to refer it.(use global variable $Resource).

Solution:- Use Below code to refer this.
   public String getHeader() {
        
        return [Select Body,Name From Document Where Name  = 'Header'].Body.toString();
    }
  
  
    public String getFooter() {
        
        return [Select Body,Name From Document Where Name= 'Footer'].Body.toString();
    }

In visual-force 
<apex:outputText value="{!Header}" escape="false"/>
<apex:outputText value="{!Footer}" escape="false"/>

It is quite simple,is not it ?????

No comments: