Salesforce - Static Resources



The user interface in a Visualforce base can display dynamic content the value of which keeps changing based on user responses. But there are times when we need some content which should not change with the change in values of other components in the page. For example, an image file may be required to remain constant. Such content which cannot be changed in a page is known as a static resource.

Following are a few static resources in Salesforce −

  • Images
  • Javascript Files
  • Flash files
  • CSS files

The steps to create a static resource are as below.

Create a Static Resource container

Go to Develop → Static resource and mention the values for name, description and file location for the static resource.

Startic Resource 1

Upload a Static Resource

Click Save in the above screen to get the file attached to the User Interface controller.

Static Resource

Reference the Static Resource

Next we create the apex code as in the following screenshot to reference the static object we created above.

Startic Resource Code

Output

Running the above apex code will generate the following output. The output shows a static resource.

Startic Resource Result
Advertisements