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
Stephanie Boggs 17Stephanie Boggs 17 

Increase File Size on VF Document Upload

Hello,

I am using the following code I found online, and I get an error when attempting to upload a document that is more than 135KB. I do not have apex coding skills, so I am having a tough time altering the code myself. I have found some forums that go over fixes to other similar code but not sure where to make what changes to what I have. Also, if I could get a "Your document has been uploaded" message inline I would be so thankful! There is nothing that informs the users it's been uploaded and they are uploading the file(s) multiple times.

Apex Class:
public class attachmentsample {

    public attachmentsample(ApexPages.StandardController controller) {

    }
    Public Attachment myfile;
    Public Attachment getmyfile()
    {
        myfile = new Attachment();
        return myfile;
    }
   
    Public Pagereference Savedoc()
    {
        String accid = System.currentPagereference().getParameters().get('id');

        Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body);
         
         /* insert the attachment */
         insert a;
        return NULL;
    }   

}

Visualforce Page: (I have other VF code, but this is the part that is affected by what I am attempting to do.)
</apex:pageBlockSectionItem>
<apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}" />
<apex:commandbutton value="Attach File" action="{!Savedoc}"/>
</apex:pageblocksection>
Alain CabonAlain Cabon
Hello Stephanie,

135KB is the limit size of the view state.  The view state of a web page is composed of all the data that's necessary to maintain the state of the controller during server requests (like sending or receiving data).

<apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}" /> : limit 10 MB

In fact, the standard popup used for adding an attachment in Salesforce can by-pass the view state limit because it is not a Visualforce page .

"Notes & Attachments" is a related list which exists for all the custom objects but not in the layouts by default.

Just add this related list to your layout.

User-added image

Best regards
Alain
Stephanie Boggs 17Stephanie Boggs 17
I do have a Notes and Attachments related list on the standard page, but the VF page is a form submission and has a section that says if they have not yet attached the proposal they need to do so now (prior to submitting the approval request). 
Stephanie Boggs 17Stephanie Boggs 17
I found that I could use <apex:relatedList subject="{!account}" list="CombinedAttachments" /> to add the actual related list (I wish I found this months ago), but this clears any input field changes made on the visualforce page. Is there a way to allow the attachment to not reset the changes to the input fields but allow more than 135KB files?
Alain CabonAlain Cabon
If you add the related list into your "editing" visualforce page, you will always open a new page like for a "detail" record standard page.

From a standard detail record page, you can edit some fields (inline editing) and ... save the modifications before adding an attachment opening a new page (from where you can return without loosing the modifications).

I know very well this problem and the solution is not given!  ( perhaps a free solution with appexchange: https://appexchange.salesforce.com (https://appexchange.salesforce.com  ) )

Otherwise you need to open a pop-up for adding attachments (it is a javascript solution, a non standard solution).

That works fine but it is not supported by Salesforce which can change the name and the internal mechanism of its filepicker_fs.jsp (java technology, it is not a visualforce page).

http://salesforce.stackexchange.com/questions/13112/how-to-specify-attachments-related-list-in-a-vf-page
 
function openDocumentUpload(e) {
   setLastMousePosition(e);
   openPopup('/widg/filepicker_fs.jsp?lktp=015&mode=1&eid=00Yg0000000aN7g&utype=00P&omode=1&otype=2', 'doc', 450, 450, 'width=450,height=450,scrollbars=yes,toolbar=no,status=no,directories=no,menubar=no,resizable=1', true);
}

Solution written by http://salesforce.stackexchange.com/users/2212/crmprogdev

It is not given because you cannot use this solution directly, there are some problems with this javascript and the parameter passings between your visualforce page and this javascript code.

Alain