You need to sign in to do that
Don't have an account?
Lavanya
how to create a Vf page to upload a data file
Hi All, I am trying to create VF page which has two button "search" and "upload". when i click the "search" button i want it to search the data file stored in mt system. Then i click "upload" which is to upload a data file stored in our system . It is same as the upload files option in gmail. kindly help me to resolve this issue. Thanks , Regards, lavanya.
HI Lavanya,
You could use <apex:inputFile> tag to fetch the standarad file-select popup. Further you might want to write the code for inserting the record to "Attachments" object in Salesforce. Let me know in case you need more clarification.
Thanks,
Srinath T
Hi,
You can go through the below code
Thanks,
Devendra
Hi Devendra, thanks for the reply.
I am getting this error.
Error: Compile Error: Non-void method might not return a value or might have statement after a return statement. at line 82 column 13
code:
public class FileUploadController
{
private String fileName;
private Integer fileSize;
private Blob fileBody;
public FileUploadController(ApexPages.StandardController controller){}
public FileUploadController(){}
public String getFileName()
{
return this.fileName;
}
public void setFileName(String fileName)
{
this.fileName = fileName;
}
public Blob getFileBody()
{
return this.fileBody;
}
public void setFileBody(Blob fileBody)
{
this.fileBody = fileBody;
setFileSize(this.fileBody.size());
}
public Integer getFileSize()
{
return this.fileSize;
}
public void setFileSize(Integer fileSize)
{
this.fileSize = fileSize;
}
private Database.SaveResult insertUpload()
{
Upload__c uploadObj = new Upload__c();
// fill out cust obj fields
return Database.insert(uploadObj);
}
private Database.SaveResult insertAttachment(Id parentId)
{
Database.SaveResult result;
Attachment attachment = new Attachment();
attachment.Body = this.fileBody;
attachment.Name = this.fileName;
attachment.ParentId = parentId;
result = Database.insert(attachment);
fileBody = Blob.valueOf(' ');
return result;
}
public PageReference processUpload()
{
try
{
Database.SaveResult result = insertUpload();
if (result == null || !result.isSuccess())
{
return null;
}
result = insertAttachment(result.getId());
if (result == null || !result.isSuccess())
{
return null;
}
}
catch (Exception e)
{
ApexPages.AddMessages(e);
}
//return Url();
}
}
Kindly any one tell how to resolve this.
Thanks,
Regards,
Lavanya.