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
Naveen MadaanNaveen Madaan 

wants to insert and display the records of a csv file in VF page

Hi I am uploading a csv file in visual force page and also wants to display the records on page, but while displaying the data i am getting error of regex too complicated or out of bound index. my file contains 32 columns and 834 rows.

Can any one provide me the solution for this.
my apex code is : <apex:page sidebar="true" controller="FileUploader">
   <apex:form >
      <apex:sectionHeader title="Upload data from CSV file"/>
      <apex:pagemessages />
      <apex:pageBlock >
              <apex:inputFile value="{!contentFile}" filename="{!nameFile}" /> 
              <apex:commandButton action="{!ReadFile}" value="Upload File" id="theButton" style="width:70px;"/>
      <apex:pageblocktable value="{!uploadedAccounts}" var="acc">
              <apex:column value="{!acc.address__c}"/>
              <apex:column value="{!acc.Bathrooms__c}"/>
              <apex:column value="{!acc.bedrooms__c}"/>
         <apex:column value="{!acc.call_attempt__c}"/>
         <apex:column value="{!acc.city__c}"/>
         <apex:column value="{!acc.create_date__c}"/>
           <apex:column value="{!acc.Full_name__c}"/>
            <apex:column value="{!acc.last_call_date__c}"/>
         <apex:column value="{!acc.last_call_result__c}"/>
         <apex:column value="{!acc.list_agent__c}"/>
         <apex:column value="{!acc.listing_status__c}"/>
          <apex:column value="{!acc.list__c}"/>
         <apex:column value="{!acc.list_price__c}"/>
          <apex:column value="{!acc.MLS_ID__c}"/>
          <apex:column value="{!acc.MLS_name__c}"/>
       <apex:column value="{!acc.notes__c}"/>
         <apex:column value="{!acc.phone_1__c}"/>
          <apex:column value="{!acc.phone_2__c}"/>
          <apex:column value="{!acc.phone_3__c}"/>
           <apex:column value="{!acc.property_type__c}"/>
          <apex:column value="{!acc.source__c}"/>
          <apex:column value="{!acc.square_footage__c}"/>
             <apex:column value="{!acc.state__c}"/>
             <apex:column value="{!acc.status_change_date__c}"/>
         <apex:column value="{!acc.tax_address__c}"/>
         <apex:column value="{!acc.tax_city__c}"/>
         <apex:column value="{!acc.tax_name__c}"/>
         <apex:column value="{!acc.tax_postal_code__c}"/>
         <apex:column value="{!acc.tax_srate__c}"/>
             <apex:column value="{!acc.Zip_code__c}"/>

and class is :
public class FileUploader 
    public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    String[] filelines = new String[]{};
    List<real__c> accstoupload;
    public Pagereference ReadFile()
        filelines = nameFile.split('\n');
        accstoupload = new List<real__c>();
        for (Integer i=1;i<filelines.size();i++)
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
            real__c a = new real__c();
            a.phone_1__c = inputvalues[0]; 
            a.phone_2__c = inputvalues[1];        
            a.phone_3__c = inputvalues[2];
        insert accstoupload;
        catch (Exception e)
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
        return null;
    public List<real__c> getuploadedAccounts()
        if (accstoupload!= NULL)
            if (accstoupload.size() > 0)
                return accstoupload;
                return null;                    
            return null;
Justin RuckJustin Ruck
What I would do is create an object where I could upload the CSV file.  Then, I would insert the custom object into the VisualForce page.