Saturday, June 28, 2014

What is Transient Variable in Salesforce?

What is  Transient Variable in Salesforce?

Transient Variable in Sales force:
        Transient keyword to declare instance variable that can not be saved and should not transmitted as part of view state for visual force page.

View state maintains state of the Database between request and visual force page.

     Given below example is use of transient variable where we have created two Date Time and populating. Refresh button is using for refresh the VF page however only time T2 will change at because of this is declare as transient.

VF Page:

<apex:page controller="ExampleController">
  T1: {!t1} <br/>
  T2: {!t2} <br/>
  <apex:form >
    <apex:commandLink value="refresh"/>

Controller :

public class ExampleController {

    DateTime t1;
    transient DateTime t2;

    public String getT1() {
        if (t1 == null) t1 =;
        return '' + t1;

    public String getT2() {
        if (t2 == null) t2 =;
        return '' + t2;


Post a Comment

| ,