function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael DsozaMichael Dsoza 

View State Error (Crossing 135 KB size)

Hi,

In my VF page, I am displaying list of images (Attachments) using pageBlockTable. While displaying images, At some images, it takes very small size to display image but in some images it takes very huge size of KB's as a result view state error appears as it is crossing view state limit of 135KB.
common.udd.object.EncryptableF... size takes 0.27 kb 
core.filemanager.ByteBlobValue... size takes 27.45 kb 

View State Details

Thanks
Best Answer chosen by Michael Dsoza
Amit Chaudhary 8Amit Chaudhary 8
To reduce View Statu issue try to fatch only PIC URL not body like below code.

The image can be displayed in the VF page by using <apex : image> tag. Image source is specified by "URL" attribute.
But the url should be in the form : " /servlet/servlet.FileDownload?file=xxxxxxxxxxx" where  xxxxxxxxxxx is the the unique id of theDocument/Attachment record containing the image.

Example 1:-
Visual Force Page :
=====================

<apex:page controller="ImageController" showheader="false" sidebar="false">
 
    <apex:form>
      <apex:image url="{!imageURL}">
    </apex:image></apex:form>
 
</apex:page>
========================

Controller :
=================================
public with sharing class ImageController {
 public String imageURL{get;set;}
   
  public ImageController()
  {
    imageURL='/servlet/servlet.FileDownload?file=';
    List< document > documentList=[select name from document where 
                                    Name='SamplePic'];
   
    if(documentList.size()>0)
    {
      imageURL=imageURL+documentList[0].id;
    }
  }
}
====================================

Example 2:-
Public Class displayImageExtension {

    String recId;
    
    public displayImageExtension(ApexPages.StandardController controller) {
        recId = controller.getId();    
    }
    
    public String getFileId() {
        String fileId = '';
        List<Attachment> attachedFiles = [select Id from Attachment where parentId =:recId order By LastModifiedDate DESC limit 1];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
            fileId = attachedFiles[0].Id;
        }
        return fileId;    
    }
}

Visual Force Page

<apex:page standardController="Account" extensions="AccountImageController">
<apex:form >
<apex:image url="/servlet/servlet.FileDownload?file={!FileId}"/>
</apex:form>
</apex:page>



http://salesforce.stackexchange.com/questions/4537/how-to-reduce-a-large-internal-view-state-what-is-in-the-internal-view-state
https://help.salesforce.com/apex/HTViewSolution?id=000113345&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000113345&language=en_US)
https://developer.salesforce.com/forums/ForumsMain?id=906F000000099XCIAY
Please let us know if this will help you.
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
To reduce View Statu issue try to fatch only PIC URL not body like below code.

The image can be displayed in the VF page by using <apex : image> tag. Image source is specified by "URL" attribute.
But the url should be in the form : " /servlet/servlet.FileDownload?file=xxxxxxxxxxx" where  xxxxxxxxxxx is the the unique id of theDocument/Attachment record containing the image.

Example 1:-
Visual Force Page :
=====================

<apex:page controller="ImageController" showheader="false" sidebar="false">
 
    <apex:form>
      <apex:image url="{!imageURL}">
    </apex:image></apex:form>
 
</apex:page>
========================

Controller :
=================================
public with sharing class ImageController {
 public String imageURL{get;set;}
   
  public ImageController()
  {
    imageURL='/servlet/servlet.FileDownload?file=';
    List< document > documentList=[select name from document where 
                                    Name='SamplePic'];
   
    if(documentList.size()>0)
    {
      imageURL=imageURL+documentList[0].id;
    }
  }
}
====================================

Example 2:-
Public Class displayImageExtension {

    String recId;
    
    public displayImageExtension(ApexPages.StandardController controller) {
        recId = controller.getId();    
    }
    
    public String getFileId() {
        String fileId = '';
        List<Attachment> attachedFiles = [select Id from Attachment where parentId =:recId order By LastModifiedDate DESC limit 1];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
            fileId = attachedFiles[0].Id;
        }
        return fileId;    
    }
}

Visual Force Page

<apex:page standardController="Account" extensions="AccountImageController">
<apex:form >
<apex:image url="/servlet/servlet.FileDownload?file={!FileId}"/>
</apex:form>
</apex:page>



http://salesforce.stackexchange.com/questions/4537/how-to-reduce-a-large-internal-view-state-what-is-in-the-internal-view-state
https://help.salesforce.com/apex/HTViewSolution?id=000113345&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000113345&language=en_US)
https://developer.salesforce.com/forums/ForumsMain?id=906F000000099XCIAY
Please let us know if this will help you.
 
This was selected as the best answer
surasura
mark your image list variable as Transient .
eg :  Transient List<attacnment> images

please refer https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_transient.htm for more information and examples