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
anukarthi_nimmalaanukarthi_nimmala 

Regarding passing csv file fields to a customobject dynamically by using apex controller

Hi i have a csv file with field values as each column in csv file which i upload to documents tab.Now  instead of using import wizard for importing the csv field values to the custom object, I want to pass the column values  of csv file in to controller and then insert the values in to custom object up on a button action.

 

 

Difficulty what iam facing here is how to pass the column values from documents tab in to the controller.Is it possible to do it?

If so plz guide me how to do that with a sample code to achieve  this.

 

 

 

                                                                                                                                                                       Thanks and regards,

                                                                                                                                                                                     anu..

 

 

 

 

 

 

SargeSarge

Hi,

 

   Check this link for Parsing CSV using Apex

 

     http://wiki.developerforce.com/index.php/Code_Samples#Parse_a_CSV_with_APEX

 

Once you have parsed the csv, the element 0 in result (List<List<String>>) are the headers and hence the column values needed for your code.

anukarthi_nimmalaanukarthi_nimmala

Hi Sarge,

 

 Thanks a  lot for the reply, i have tried it out but iam facing aproblem in findingh out the solution.I need to parse the csv document which i uploaded so how to pass the uploaded to this function whatever given in the code as its given  in a genarilised way.now i want to parse the file which i uploaded to documents tab.SO plz help me out to come out of the issue with solution.

 

                                                                                                                                                                                 Thanks and regards,

                                                                                                                                                                                               Anu..

SargeSarge

Use the SOQL query

 

Document d = [Select Name,Body from Document where Name = 'uploaded.csv'];

 

I hope you know which document record you are referring. Filter it appropriatley.

 

 

Blob csvFile = d.body;

 

List<List<String>> result = ParseCSVClass.parseCSV(csvFile.toString(), false);

 

now you have the paersed CSV result.

 

now use result[0] to get the headers.

 

Cheers..