Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Can we upload a file from visualforce sites into salesforce? Can anyone tell me the procedure / provide the sample code.
Thanks.
You can find the sample code here
Try out the sample code given below :
VF code:
<apex:form >
<apex:pageBlock title="Upload New Attachment">
<table>
<tr>
<td class="rows" >Browse For File</td>
<td><apex:inputFile value="{!filebody}" fileName="{!filename}" /></td>
</tr>
<td></td>
<td align="left"><apex:commandButton action="{!uploadfile}" value="Upload"/></td>
</table>
</apex:pageBlock>
</apex:form>
Controller code:
public string parentid { get; set; }
public string filename { get; set; }
public blob filebody { get; set; }
public void uploadfile()
{
if(filebody != null && filename != null && filename != '')
transient Attachment a = new Attachment();
a.body = filebody;
a.name = filename;
a.parentid = ApexPages.currentPage().getParameters().get('id');
try
insert a;
filename = '';
filebody = null;
}
catch(Exception e)
Hope this helps.
Thank you all for your replies. I will try to implement the code that you have provided and will let you know.
Again Thank's a lot.
You can find the sample code here
All Answers
You can find the sample code here
Try out the sample code given below :
VF code:
<apex:form >
<apex:pageBlock title="Upload New Attachment">
<table>
<tr>
<td class="rows" >Browse For File</td>
<td><apex:inputFile value="{!filebody}" fileName="{!filename}" /></td>
</tr>
<tr>
<td></td>
<td align="left"><apex:commandButton action="{!uploadfile}" value="Upload"/></td>
</tr>
</table>
</apex:pageBlock>
</apex:form>
Controller code:
public string parentid { get; set; }
public string filename { get; set; }
public blob filebody { get; set; }
public void uploadfile()
{
if(filebody != null && filename != null && filename != '')
{
transient Attachment a = new Attachment();
a.body = filebody;
a.name = filename;
a.parentid = ApexPages.currentPage().getParameters().get('id');
try
{
insert a;
filename = '';
filebody = null;
}
catch(Exception e)
{
}
}
}
Hope this helps.
Thank you all for your replies. I will try to implement the code that you have provided and will let you know.
Again Thank's a lot.