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
Salesforce Test 5Salesforce Test 5 

135KB Limitation

Hi All
I have created a vf page  for file uploading.its working fine,but when i am uploading more than 135KB file its throwing error
Maximum view state size limit (135KB) exceeded
 
<apex:page standardController="Purchase_Order__c" extensions="NewSalesConfirmationExtension">
    <apex:sectionHeader title="Sale Confirmation Orders" subtitle="{!purchaseOrder.Name}" />
    <apex:form >
        <apex:pageMessages ></apex:pageMessages>
        <apex:pageBlock title="Sale Confirmation Order Edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockSection title="Information" columns="2" collapsible="false" rendered="{!showC1RecordType}">
                <apex:inputField value="{!purchaseOrder.Opportunity__c}"/>
                <apex:inputField value="{!purchaseOrder.Sale_Confirmation_Order_Number__c}" required="true"/>
                <apex:inputField value="{!purchaseOrder.GRN_needed_for_Bill_Processing__c}"/>
                <apex:inputField value="{!purchaseOrder.Sale_Confirmation_Order_Date__c}" required="true"/>
                <apex:inputField value="{!purchaseOrder.No_of_Days_for_collecting_GRN__c}"/>
                <apex:inputField value="{!purchaseOrder.Pre_shipment_Inspection_required__c}" required="true" />
              
                <apex:inputField value="{!purchaseOrder.Purchase_Frequency__c}" required="true" />
                <apex:inputField value="{!purchaseOrder.Customer_Ordered_Quantity__c}" required="true" />
                <apex:inputField value="{!purchaseOrder.Credit_Limit__c}"/>
                   
                    <apex:inputField value="{!purchaseOrder.Customer_Price__c}"/>
                     <apex:inputField value="{!purchaseOrder.CurrencyIsoCode}"/>
                <apex:inputField value="{!purchaseOrder.Bill_Submission_Period__c}"/>
               
                <!---<apex:inputField value="{!purchaseOrder.New_Flash_Aidc_Email_sent__c}"/>--->
               
               
               <!--- <apex:inputField value="{!purchaseOrder.New_Flash_Email_sent__c}"/>--->
                <apex:inputField value="{!purchaseOrder.Committed_Dispatch_Date__c}" required="true"/>
              
               <!-- <apex:inputField value="{!purchaseOrder.PO_Uploaded__c}"/>
                <apex:inputField value="{!purchaseOrder.Try__c}"/>
                <apex:inputField value="{!purchaseOrder.CountAttachment__c}"/>--->
            </apex:PageBlockSection>
            
            <apex:pageBlockSection title="Information" columns="2" collapsible="false" rendered="{!showC2RecordType}">
                <apex:inputField value="{!purchaseOrder.Opportunity__c}"/>
                <apex:inputField value="{!purchaseOrder.Sale_Confirmation_Order_Number__c}" required="true"/>
                <apex:inputField value="{!purchaseOrder.GRN_needed_for_Bill_Processing__c}"/>
                <apex:inputField value="{!purchaseOrder.Sale_Confirmation_Order_Date__c}" required="true"/>
                <apex:inputField value="{!purchaseOrder.No_of_Days_for_collecting_GRN__c}"/>
                <apex:inputField value="{!purchaseOrder.Committed_Dispatch_Date__c}" required="true"/>
                <apex:inputField value="{!purchaseOrder.Credit_Limit__c}"/>
                <apex:inputField value="{!purchaseOrder.Customer_Ordered_Quantity__c}"/>
                <apex:inputField value="{!purchaseOrder.CurrencyIsoCode}"/>
                <apex:inputField value="{!purchaseOrder.Customer_Price__c}"/>
                <apex:inputField value="{!purchaseOrder.Purchase_Frequency__c}" required="true" />
                <apex:inputField value="{!purchaseOrder.Bill_Submission_Period__c}"/>
                <apex:inputField value="{!purchaseOrder.Application_Area__c}"/>
               
                <!---<apex:inputField value="{!purchaseOrder.CountAttachment__c}"/>
                <apex:inputField value="{!purchaseOrder.Try__c}"/>
                <apex:inputField value="{!purchaseOrder.New_Flash_Email_sent__c}"/>
                 <apex:inputField value="{!purchaseOrder.New_Flash_Aidc_Email_sent__c}"/>---->
            </apex:PageBlockSection>
            
            <apex:pageBlockSection title="Quote Details" columns="1" collapsible="false">
                <apex:inputField value="{!purchaseOrder.Quote__c}"/>
                <apex:inputField value="{!purchaseOrder.Company__c}"/>
                 <apex:inputField value="{!purchaseOrder.Delivery_Address__c}" required="true" />
            </apex:PageBlockSection>
            
            <apex:pageBlockSection title="New Flash Details" columns="2" collapsible="false">
                <apex:inputField value="{!purchaseOrder.Application_Area__c}"  rendered="{!showC1RecordType}"/>
                <apex:inputField value="{!purchaseOrder.Remarks__c}"/>
            </apex:PageBlockSection>
            
            <apex:pageBlockSection title="Upload Purchase Order" columns="2" collapsible="false">
                <apex:pageBlockSectionItem >
                <apex:outputLabel value="File" for="file" />
                <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
                </apex:pageBlockSectionItem>
            </apex:PageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>


-------------------------------------------------------------------------------


public class NewSalesConfirmationExtension {
    public Purchase_Order__c purchaseOrder{get;set;}
    public Attachment attachment {get;set;}
    public boolean showC1RecordType {get;set;}
    public boolean showC2RecordType {get;set;} 
    
    private Id c1RecordTypeId; 
    private Id c2RecordTypeId;
    
    public NewSalesConfirmationExtension(ApexPages.StandardController controller) {
        c1RecordTypeId = Schema.SObjectType.Purchase_Order__c.getRecordTypeInfosByName().get('C1').getRecordTypeId();
        c2RecordTypeId = Schema.SObjectType.Purchase_Order__c.getRecordTypeInfosByName().get('C2').getRecordTypeId();
        
        purchaseOrder = new Purchase_Order__c();
        purchaseOrder = (Purchase_Order__c)controller.getRecord();
        
        String isButtonClicked = Apexpages.currentPage().getParameters().get('setDefaultValues');
        if(isButtonClicked == 'true'){
            setDefaultValues();
        }
        
        showC1RecordType = false;
        showC2RecordType = false;
        attachment = new Attachment();
        
        
        if(purchaseOrder.RecordTypeId == c1RecordTypeId){
            showC1RecordType = true;
            showC2RecordType = false;
        }
        else if(purchaseOrder.RecordTypeId == c2RecordTypeId){
            showC1RecordType = false;
            showC2RecordType = true;
        }
        
    }
    
     public void setDefaultValues(){
        String quoteId = Apexpages.currentPage().getParameters().get('quoteId');
        Quote__c quote = [Select o.id, o.name, o.Quantity_formula__c, o.Opportunity_Product_Detail__r.Opportunity__c,
                    o.Opportunity__c, o.Record_type_name__c,o.Company_Name__c,Opportunity_Product_Detail__r.Opportunity__r.Account__c from Quote__c o WHERE O.id=:quoteId];
        //system.assert(false,quote);     
        purchaseOrder.Opportunity__c = quote.Opportunity_Product_Detail__r.Opportunity__c;
        purchaseOrder.Quote__c = quote.id;
        purchaseOrder.Company__c = quote.Opportunity_Product_Detail__r.Opportunity__r.Account__c;
        
        if(quote.Record_type_name__c == 'C1'){
            purchaseOrder.RecordTypeId = c1RecordTypeId;
        }
        else {
            purchaseOrder.RecordTypeId = c2RecordTypeId;
        }
    }
    public PageReference save(){
        if(attachment.Body == null){
            Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, 'Please upload recent Purchase Order  before saving the record'));
            return null;
        }
        else{
            try{
                insert purchaseOrder;
                
                attachment.OwnerId = UserInfo.getUserId();
                attachment.ParentId = purchaseOrder.id;
                insert attachment;
                
                return new PageReference('/'+purchaseOrder.id);
            }
            catch(DMLException e){
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,e.getMessage()));
                return null;
            }
        }
    }
}

 
Becka DBecka D
Here is an article that might help to explain the error that you are seeing: http://wiki.developerforce.com/page/An_Introduction_to_Visualforce_View_State
 
Swayam@SalesforceGuySwayam@SalesforceGuy
Hi,

Try by replacing  <apex:form > tag by <apex:form enctype="multipart/form-data"> this will create exception for view state .


Hope this help

--
Regards,
@Salesforceguy
Salesforce Test 5Salesforce Test 5
Hi Salesforceguy

I have tried this by replacing <apex:form > tag by <apex:form enctype="multipart/form-data">
.same thing is happening.  It is showing error
Maximum view state size limit (135KB) exceeded