Monday, December 12, 2016

Visualforce - Beyond Basics Series 14 - Page not just for tags

What the page can contain ?

In broad sense, visualforce page contains visualforce tags & optionally html, css & javascript. Most developers expect it to contain that standard HTML page contains.

Can it contain other than HTML contents ?

yes. visualforce is not designed to be just the HTML content. It could be following,

  •   PDF
  •   Javascript
  •   CSS
  •   CSV
  •   MS Word

It could be any type that W3 standard supports.

How to achieve that ?

we need to pass the content type attribute to the page tag. Then, it will expect the content to be in that format.


Where is the code ?

For illustration, i have given the page for csv file & javascript. When you load this page, these pages will get downloaded, because, it's not a html page & cannot be loaded.


<apex:page contentType="text/csv#MyReportData.csv">
Id, Name, Date, IsClosed
0a123432434, TestOpp, 12/12/2016, true
</apex:page>
view raw gistfile1.txt hosted with ❤ by GitHub
<apex:page contentType="text/javascript#MyScript.js">
function globalFunction() {
alert('Hi, im global function');
}
</apex:page>
view raw gistfile1.txt hosted with ❤ by GitHub
   

No comments:

Post a Comment

Thanks for reading my blog !