function readOnly(count){ }
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
<apex:page controller="Upload_CSV_File_Controller"> <apex:form > <apex:pagemessages /> <apex:pageBlock > <apex:pageBlockSection columns="4"> <apex:inputFile value="{!csvFileBody}" filename="{!csvAsString}"/> <apex:commandButton value="Upload" action="{!UploadCsvFile}"/> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock > <apex:pageblocktable value="{!LeadList}" var="ld"> <apex:column value="{!ld.FirstName}" /> <apex:column value="{!ld.LastName}" /> <apex:column value="{!ld.Company}" /> <apex:column value="{!ld.Phone}" /> </apex:pageblocktable> </apex:pageBlock> </apex:form> </apex:page> Controller: public with sharing class Upload_CSV_File_Controller { public Blob csvFileBody{get;set;} public string csvAsString{get;set;} public String[] csvFileLines{get;set;} public List<Lead> LeadList{get;set;} public Upload_CSV_File_Controller(){ csvFileLines = new String[]{}; LeadList = New List<Lead>(); } public void UploadCsvFile(){ try{ csvAsString = csvFileBody.toString(); csvFileLines = csvAsString.split('\n'); for(Integer i=1;i<csvFileLines.size();i++){ Lead LeadObj = new Lead() ; string[] csvRecordData = csvFileLines[i].split(','); LeadObj.FirstName = csvRecordData[0] ; LeadObj.LastName = csvRecordData[1]; LeadObj.Company = csvRecordData[2]; LeadObj.Phone = csvRecordData[3]; Leadlist.add(LeadObj); } insert Leadlist; } catch (Exception e) { ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct'); ApexPages.addMessage(errorMessage); } } }
Try this,
It's very nice.................but actually i have been trying the upload the multiple files using single upload button in UI...........
http://bobbuzzard.blogspot.in/search/label/Salesforce%20Attachment%20Upload%20Multiple%20Files%20Blob%20Visualforce%20Apex