Activity Forums Salesforce® Discussions Transient Keyword in #Salesforce

  • Transient Keyword in #Salesforce

  • Parul

    Member
    August 29, 2018 at 6:05 am

    What is the use of Transient Keyword in #Salesforce?

  • Anjali

    Member
    August 29, 2018 at 6:10 am

    Hi Parul,

    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: Transient 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.

     

  • shariq

    Member
    September 16, 2018 at 1:07 pm

    Hi,

    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.

    Hope this helps.

  • Prachi

    Member
    September 18, 2018 at 1:14 pm

    hi,

    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:
    Transient 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.

    thanks

Viewing 1 - 4 of 4 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos