Salesforce | Read csv file, insert objects and get results back in Apex visualforce page

|
| By Webner

If you have a csv file with raw data and you want to read it using apex, convert to sfdc objects and insert these, then get success and failure results back then following steps and code can help you:

 

1. Create an Apex Class which will read the csv file.

/***This function reads the CSV file and inserts records into the Contact object. ***/
public Pagereference ReadFile() { try{ //Convert the uploaded file which is in BLOB format into a string nameFile =blobToString( contentFile,'ISO-8859-1'); //Now separate every row of the excel file fileLines = nameFile.split('n'); //Iterate through every line and create a Contact record for each row contactsToUpload = new List(); for (Integer i=1;i

Leave a Reply

Your email address will not be published. Required fields are marked *