Aptitude (12) C (2) C++ (10) CSS (1) Data Structure (2) English (7) General (14) HTML (3) Integration (1) Itinerary and Travel Cost (1) Java (29) JQ (5) JS (5) JSP (1) Lightning (14) logical (3) Math (1) Music Notation (17) MySql (4) Network (1) Regex (1) salesforce (131) Servlet (4) SF Admin (31) SF Dev (102) SQL (4) SQL_SERVER (1) StudyPoints (2) ytChannels (2) अन्ताक्षरी (4)

Using the transient Keyword

Use the transient keyword to declare instance variables that can't be saved, and shouldn't be transmitted as part of the view state for a Visualforce page. For example:

1Transient Integer currentTotal;
You can also use the transient keyword in Apex classes that are serializable, namely in controllers, controller extensions, or classes that implement the Batchable or Schedulable interface. In addition, you can use transient in classes that define the types of fields declared in the serializable classes.
Declaring variables as transient reduces view state size. A common use case for the transient keyword is a field on a Visualforce page that is needed only for the duration of a page request, but should not be part of the page's view state and would use too many system resources to be recomputed many times during a request.
Some Apex objects are automatically considered transient, that is, their value does not get saved as part of the page's view state. These objects include the following:
  • PageReferences
  • XmlStream classes
  • Collections automatically marked as transient only if the type of object that they hold is automatically marked as transient, such as a collection of Savepoints
  • Most of the objects generated by system methods, such as Schema.getGlobalDescribe.
  • JSONParser class instances.
Static variables also don't get transmitted through the view state.
The following example contains both a Visualforce page and a custom controller. Clicking the refresh button on the page causes the transient date to be updated because it is being recreated each time the page is refreshed. The non-transient date continues to have its original value, which has been deserialized from the view state, so it remains the same.
1<apex:page controller="ExampleController">
2  T1: {!t1} <br/>
3  T2: {!t2} <br/>
4  <apex:form>
5    <apex:commandLink value="refresh"/>
6  </apex:form>
01public class ExampleController {
03    DateTime t1;
04    transient DateTime t2;
06    public String getT1() {
07        if (t1 == null) t1 = System.now();
08        return '' + t1;
09    }
11    public String getT2() {
12        if (t2 == null) t2 = System.now();
13        return '' + t2;
14    }


Sherry Beck said...

It’s amazing in support of me to truly have a web site that is valuable meant for my knowledge.

Mehak Shaikh said...

Awesome execute using this web together with search engine optimization company's assistance http://www.truebridge.com/2014/11/engagement-marketing/ Constructed an amazing web site plus a strong marketing campaign that essential our organization to another level, Advise...they're driven along with beneficial!

Rocky said...

I'm in no doubt coming back again to read these articles and blogs.

Fastlane Central said...

The team is in a position to manage complex processes UX agency work. They often produce extra deliverables and new ideas because they realize it will help the business.

Robert Oldham said...

I feel happiness to read the content that you are posting.
imp source

Leslie Thompson said...

Great! We will be connecting to this enormous post on our site. Continue the good writing.
lead conversion system review