Tag Archives: Visualforce Page

Pass Parameters From One Visualforce Page To Another Visualforce Page

First Visualforce Page:

<apex:page>
    <apex:outputLink value="/apex/SecondPage">Click Here
    	<apex:param name="name" value="Biswajeet Samal"/>
    </apex:outputLink>
</apex:page>

Second Visualforce Page:

<apex:page controller="SecondPageController">
    Hello {!name}
</apex:page>

Second Page Controller:

public class SecondPageController {
    public String name {get;set;}
    
    //Constructor
    public SecondPageController(){
        name = System.currentPageReference().getParameters().get('name');
    }
}

Pass variable to a custom label from visualforce page

To know more about custom label Click here
Step 1:
Go to Setup –> App Setup –> Custom Labels.
Step 2:

1

Step 3:
Here for dynamic populate custom label variable value, the custom label value has written like this “My name is {0} {1}”.

2

Step 4:
Now I’ll create an apex controller with two variable to send it custom label.

public class TestCustomLabel{
    public string FirstName{get;set;}
    public string LastName{get;set;}    
     
    public TestCustomLabel(){
        FirstName = 'Biswajeet';
        LastName = 'Samal';
    }
}

Step 5:
Now I’ll create a visualforce page and use the custom label with parameters in it. Here the first parameter “FirstName” is for custom label “{0}” and the second parameter “LastName” is for custom label “{1}”.

<apex:page controller="TestCustomLabel" tabstyle="Account">
    <apex:form>
        <apex:pageblock>
            <apex:outputtext value="{!$Label.TestCustomLabel}">
            <apex:param value="{!FirstName}">
            <apex:param value="{!LastName}">
            </apex:param></apex:param></apex:outputtext>
        </apex:pageblock>
    </apex:form>
</apex:page>

Here is the visualforce page output:

3

Custom label in visualforce page and apex Class

Custom labels are custom text values that can be accessed from Apex classes or Visualforce pages. The value of Custom label can be static or dynamic from visulaforce page and apex class. The values can be translated into any language Salesforce supports. Custom labels enable developers to create multilingual applications by automatically presenting information (for example, help text or error messages) in a user’s native language.
In this article I’ll demonstrate how to use custom labels in visualforce page and apex classes.

Note: We can create up to 5,000 custom labels for your organization, and they can be up to 1,000 characters in length.
Step 1:
Go to Setup –> App Setup –> Custom Labels.
Step 2:

download
Step 3:

2

Step 4:
Now I’ll create a visualforce page and use the custom label in it.

<apex:page tabstyle="Account">
   <apex:form>
     <apex:pageblock>
       <apex:outputtext value="Custom lable value is : ">
       <apex:outputtext style="font-weight: bold;" value="{!$Label.DemoCustomLabel}">
     </apex:outputtext></apex:outputtext></apex:pageblock>
   </apex:form>
</apex:page>

Here is the visualforce page output:

3

Now get custom label value in apex class.

string  LabelText = System.Label.DemoCustomLabel;

Difference Between Pageblocktable, Datatable And Repeat in Salesforce

PageBlockTable:

  • PageBlockTable should be define inside apex:pageblock or apex:pageblocksection
  • PageBlockTable uses standard page styles
  • PageBlockTable has the required attribute “value”
  • Column headers will be displayed automatically

DataTable:

  • No need to write inside apex:pageblock or apex:pageblocksection
  • There is no required attribute value
  • The data can be displayed using custom styles
  • We need to specify column headers explicitly

Repeat:

  • No Salesforce styles inherited, no need to use apex:column
  • Simply data displayed in irregular format
  • You can have full control over rendering data

Render a Textbox on Selection of a Certain Value From Picklist

Visualforce Page:

<apex:page standardController="Account">
    <apex:form >
    <apex:pageBlock >
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:inputField value="{!Account.type}">
                    <apex:actionSupport event="onchange" rerender="conditionalEntryFieldDiv"/>
                </apex:inputField>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputPanel layout="block" id="conditionalEntryFieldDiv">
                    <apex:inputField value="{!Account.accountnumber}" rendered="{!Account.type == 'Prospect'}"/>
                </apex:outputPanel>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>
</apex:page>

Here in the above code, on selection of account type picklist value “Prospect” the account number field will render.

Output: