Monday 18 November 2013

Visualforce is a great for rapidly building web apps on top of Salesforce. One of the features of Visualforce is called "Satic Resource". It allows developers to add any custom Javascript, CSS and image files to Salesforce server and provide them a way to extend Visualforce capabilities to build different kinds of applications.
                  Is is a good practice to write a Javascript and save in satatic resource and include it your code.

Example :

Suppose you are creating a page and have few buttons ( save, cancel ) on the page and you want to pop up a confirmation message when user click on cancel button.
Then first create a file where you will writting all your javascript code.
I have created confirm.js which contain my javascript code 

 


 Saved that file in Static Resource, I saved my file in static resource with name wizradConfirm.



and then include that in my visualforce code. (Highlighted in red)
 <apex:page controller="oppController">
     <apex:includeScript value="{!$Resource.wizardconfirm}"/>
     <apex:form>
         <apex:pageBlock title="Opportunity Information" mode="edit">
                <apex:pageBlockButtons >
                    <apex:commandButton action="{!step1}" value="Previous"/>
                    <apex:commandButton action="{!step3}" value="Next"/>
                    <apex:commandButton action="{!Cancel}" value="Cancel"    onclick="return confirmCancel()" immediate="true"/>
                </apex:pageBlockButtons>

         </apex:pageBlock>
     </apex:form>
</apex:page>


so when User clicks cancel pop up message shows up.


1 comment: