You need to sign in to do that
Don't have an account?
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>
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>
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.
Best regards
Alain
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
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