Access URL Parameters in Salesforce
In Visualforce Page:
$CurrentPage.parameters.PARAMETERNAME
In Apex:
ApexPages.currentPage().getParameters().get('PARAMETERNAME');
In Visualforce Page:
$CurrentPage.parameters.PARAMETERNAME
In Apex:
ApexPages.currentPage().getParameters().get('PARAMETERNAME');
To create a modal dialogue box in visualforce page follow below steps.
public class TestPopup{ public boolean DisplayPopup {get; set;} public void ClosePopup() { DisplayPopup = false; } public void ShowPopup() { DisplayPopup = true; } }
<apex:page controller="TestPopup"> <apex:form> <apex:commandbutton action="{!ShowPopup}" rerender="TestPopup" value="Show Popup"> <apex:pageblock> This is a sample Test Popup Page. </apex:pageblock> <apex:outputpanel id="TestPopup"> <apex:outputpanel layout="block" rendered="{!DisplayPopUp}" styleclass="popupBackground"> <apex:outputpanel layout="block" rendered="{!DisplayPopUp}" styleclass="customPopup"> Hi, Biswajeet <apex:commandbutton action="{!ClosePopup}" rerender="TestPopup" value="Close Popup"> </apex:commandbutton></apex:outputpanel> </apex:outputpanel> </apex:outputpanel></apex:commandbutton></apex:form> <style type="text/css"> .customPopup{ background-color: white; border-width: 2px; border-style: solid; z-index: 9999; left: 50%; padding:10px; position: absolute; width: 300px; margin-left: -250px; top:100px; } .popupBackground{ background-color:black; opacity: 0.20; filter: alpha(opacity = 20); position: absolute; width: 100%; height: 100%; top: 0; left: 0; z-index: 9998; } </style> </apex:page>
Here is the output comes up:
Created Visualforce Page:
After click on the button, modal popup is displayed:
To create a new VisualForce page go to “Your Name” > Setup > Develop > Pages and click the New button.
You will now see the VisualForce page creation wizard. The very first thing you will want to do is give your new VisualForce page a Label. A label is a more esthetic name of what your page name will actually be.
Once you’ve typed your page label press the Tab key to set your cursor to the Name field. You will notice that the Name automatically took the value of “Test Page” from Label. SalesForce won’t allow you to have spaces in the name so replace your space with an Underscore character as shown below.
SalesForce will automatically give you some default VisualForce markup to work with as shown below.
<apex:page> <!-- Begin Default Content REMOVE THIS --> <h1>Congratulations</h1> This is your new Page <!-- End Default Content REMOVE THIS --> </apex:page>
Controller:
public class Sample{ public Account acc {get;set;} public List<SelectOption> typeOptions {get;set;} // Constructor called when page is accessed. public Sample() { acc = new Account(); typeOptions = new List<SelectOption>(); //Use DescribeFieldResult object to retrieve status field. Schema.DescribeFieldResult typeFieldDescription = Account.Type.getDescribe(); //For each picklist value, create a new select option for (Schema.PickListEntry pl:typeFieldDescription.getPicklistValues()){ typeOptions.add(new SelectOption(pl.getValue(),pl.getLabel())); //Obtain and assign default value if (pl.defaultValue){ acc.Type= pl.getValue(); } } } }
Visualforce Page:
<apex:page controller="Sample"> Please select account type: <br/> <apex:form > <apex:selectList size="1" value="{!acc.Type}"> <apex:selectOptions value="{!typeOptions}"/> </apex:selectList> </apex:form> </apex:page>
Here in below example I have a VF Page “AccountDetails.vf” with parameter of account Id. In that VF Page I’m showing the Account record respective Contacts. And a button that export the Contact records to excel sheet. Another VF Page “ContactExportToExcel.vf” for excel.
Viualforce Page: AccountDetails.vf
<apex:page standardController="Account" extensions="ContactExportToExcel"> <apex:form> <apex:pageBlock title="Hello {!$User.FirstName}!"> You are viewing the {!account.name} account. </apex:pageBlock> <apex:pageBlock title="Contacts"> <apex:pageBlockTable value="{!account.Contacts}" var="contact"> <apex:column value="{!contact.Name}"/> <apex:column value="{!contact.Email}"/> <apex:column value="{!contact.Phone}"/> </apex:pageBlockTable> </apex:pageBlock> <apex:commandButton value="Export To Excel" Action="{!ExportToExcel}"/> </apex:form> </apex:page>
Remember to pass an Account ID as a query string to this page.
Controller:
public with sharing class ContactExportToExcel { Public List<String> selectedFieldsList {get;set;} Public List<Contact> conList {get;set;} public ContactExportToExcel(ApexPages.StandardController stdCtrl) { Account acc = (Account)stdCtrl.getRecord(); conList = New List<Contact>(); conList = [Select Id, Name, Email, Phone From Contact Where AccountId =: acc.Id]; } Public PageReference ExportToExcel(){ selectedFieldsList = New List<string>(); selectedFieldsList.add('Name'); selectedFieldsList.add('Email'); selectedFieldsList.add('Phone'); PageReference pgRef = New Pagereference('/apex'+'/ContactExportToExcel'); pgRef.setRedirect(false); return pgRef; } }
Visualforce Page: ContactExportToExcel.vf
<apex:page standardController="Account" extensions="ContactExportToExcel" contentType="application/vnd.ms-excel#Contacts.xls" cache="true"> <apex:pageBlock > <apex:pageblocktable value="{!conList }" var="tab"> <apex:repeat value="{!selectedFieldsList}" var="field"> <apex:column value="{!tab[field]}"/> </apex:repeat> </apex:pageblocktable> </apex:pageBlock> </apex:page>