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
JBerryJBerry 

SControl upload files?

Hi,

I am creating a form for the users in our company to go and fill out a "Tech Request" ticket, which when they click the Submit button, it creates a record under a custom object that I have built.  I am doing it this way because I do not want our users directly modifying that custom object and it is full of a bunch of items they don't need.

This form consists of basics for them to fill out: Name, Problem, Description.  I am trying to add a 'File Upload" section here that they can browse their computer for, say a screenshot, and upload it along with the form.  This upload needs to be sent to the "Notes and Attachments" section of the Custom Object record they just created.

Any ideas? =)
Greg HGreg H
I had to do something very similar for a client a little over a year ago.  Basically, I hijacked the standard attachment functionality that you would use within salesforce.com to attach a file to a record.
 
Here's the form tag with some hidden inputs which will make everything work:
Code:
<form action="/p/attach/NoteAttach" enctype="multipart/form-data" id="editPage" name="editPage" method="POST">
<input type="hidden" name="cancelURL" id="cancelURL" value="/servlet/servlet.Integration?lid={!sControl.Id}">
<input type="hidden" name="pid" id="pid" value="{!Record.Id}">
<input type="hidden" name="retURL" id="retURL" value="/servlet/servlet.Integration?lid={!sControl.Id}">
<input type="hidden" name="save_new_url" id="save_new_url" value="/p/attach/NoteAttach?retURL=%2Fservlet%2Fservlet%2EIntegration%3Flid%3D{!sControl.Id}&amp;pid={!Record.Id}">

You, of course, will need to populate the record id of the record to which you want the file attached (this is the "pid" field in the code).  In addition, you will need to modify the "save_new_url" and "cancelURL" values to suite your specific needs.  In my sample I was interacting directly with my custom sControl to show that the attachment was saved - it sounds like you might do the same thing.
 
On my form I have an input field of type "file" and this allows the user to browse for the file they want to attach to a record, which in previous code (not displayed here) I've already created and now have the id for use in this code as {!Record.Id}.  Upon save, I send the user to the standard salesforce attachment upload URL "/p/attach/NoteAttach" and the hidden fields from my sample tell the attachment page what to do - the record to relate the attachment too, the page to go to upon save, and the URL to go to if an error occurs.
 
I hope you find this useful,
-greg
JBerryJBerry
Thanks! I almost have this integrated now =).  The only area I am running into an issue with is where do I insert the field name that has the file reference?  You mentioned,"



Greg H wrote:

 
On my form I have an input field of type "file" and this allows the user to browse for the file they want to attach to a record, which in previous code (not displayed here) I've already created and now have the id for use in this code as {!Record.Id}.


When I click my browse, find my file, and then click Submit, it takes me to the SF upload page telling me to select a file for upload.  When I go ahead and do it here, it attaches correctly.  I'm just at a loss of where to pass my field that contains the file =).

Thank you!
Greg HGreg H
I think it should pass the file if you use the name/id values "file":
Code:
<input type="file" title="Type the path of the file or click the Browse button to find the file." id="file" size="20" name="file">

Let me know if that works,
-greg
 
JBerryJBerry
D'oh! =) I forgot to give it the Id of file, and had only given it a name of file. That works wonderfully. Thanks for your help!!