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

Author - Webner
9.05.2018
|
0 Comments
|

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

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

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