Tuesday, 6 November 2012

How to Use Style Sheets in Visual force Pages

Step 1:

Create a CSS file.

Open NOTEPAD or any text editor and type the following code


Save the file with a .css extension (say CssExample.css)

Step 2:

Upload the saved file as a Static resource.

Setup -> Develop -> Static Resources and click on NEW.

Give a name for the static resource say CssExample. Remeber to set the Cache Control as "Public".

Step 3:

Create a visualforce page and paste the following code..

<apex:page standardstylesheets="false" showheader="false">
<apex:stylesheet value="{!$Resource.CssExample}"/>
<h1> This text is displayed using CSS </h1>

Save the page. Now you can see that the text within <h1> tag is displayed in GREEN color because you have specified so in the CSS file.

TiP: Remove showheader="false" and you can see that the text is displayed in normal size and not h1. This is because the header uses standard salesforce style sheets and your visualforce page is still overridden with this even if you say ' standardstylesheets="false" '. To overcome this use font-size:15px or whatever it maybe.
 Below attribute in <apex:page> will remove all headings use in VF page. To make it visible we have to set it to true.


Second Example:



So in the VF you can write
<apex:outputLabel Value="Account Name" styleClass="MakeBold"/>

Steps of Deployment From Salesforce site:
Lets take a example of Trigger:
As long as the Trigger works as expected in your Sandbox environment and you have adequate test coverage, I would personally use the Deployment capabitiy in Salesforce, unless you are familiar with the Eclipse IDE. For Deployments you need to make a connection between your Sandbox and Production. Go Setup>Deploy>
  1. Click Setup | Deploy | Deployment Connections.
  2. Click Edit next to the organization you want to authorize.
  3. Select Allow Inbound Changes.
  4. Click Save
Make sure that from Production you allow the inbound connection from the Sanadbox where the Trigger is and that in your Sandbox it show the outbound connection back to Production.

Now create a Outbound Change Set from your Sandbox. Give it a name and then add the Trigger to the Change Set and then deploy it to Production. Go back to Production and from the Inbound Connection make sure you actually deploy it. 

No comments:

Post a Comment

Why to use Database.Stateful()?

Database Stateful is interface. It is used in batch classes to maintain the state of the class across transactions i.e. if you want to use ...