You need to sign in to do that
Don't have an account?

How to Upload more than 135KB file in vf Page
Hi Friends
I have created a vf page which uplaod file its working fine ,but i am facing problem when file is more than 135KB.i have used transient variable also
but facing same..Is there any other way to achieve this challenge.
I have created a vf page which uplaod file its working fine ,but i am facing problem when file is more than 135KB.i have used transient variable also
but facing same..Is there any other way to achieve this challenge.
public with sharing class CCW_UploadFileController { public Purchase_Order__c purchaseOrder{get;set;} public Attachment tAttachment{get{ if(tAttachment== null) tAttachment= new Attachment(); return tAttachment; }set;} public boolean showC1RecordType {get;set;} public boolean showC2RecordType {get;set;} private Id c1RecordTypeId; private Id c2RecordTypeId; public CCW_UploadFileController(ApexPages.StandardController controller) { this.tAttachment = new Attachment(); 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; tAttachment= 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 doUploadFile(){ if(tAttachment.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; tAttachment.OwnerId = UserInfo.getUserId(); tAttachment.ParentId = purchaseOrder.id; insert tAttachment; return new PageReference('/'+purchaseOrder.id); } catch(DMLException e){ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,e.getMessage())); return null; } } } }
1) http://salesforce.stackexchange.com/questions/53112/maximum-view-state-size-limit-135kb-exceeded
2) http://forceguru.blogspot.in/2012/12/uploading-multiple-attachments-into.html
Try to make Attachment as Transient or create file uploade variable like below
Transient variables are not stored in the view state, but can be regenerated by the post back if bound to an input element. In general, you only need to use the view state for elements not bound to an input element and need to maintain state between post backs.
Please let us know if this will help you
Thanks
Amit Chaudhary
Error Message
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!doUploadFile}' in component <apex:commandButton> in page testing: Class.CCW_UploadFileController.doUploadFile: line 69, column 1
Class.CCW_UploadFileController.doUploadFile: line 69, column 1
Code