I have a requirement to insert records into custom object called Custom_Business__c using a csv file which is stored as a static resource.
Below is the code I've achieved so far
public class importDataFromCSVController {
public String[] filelines {get;set;}
public String[] nameFile {get;set;}
public importDataFromCSVController() {
Savepoint sp;
sp = Database.setSavepoint();
StaticResource FiveDigitUPCodeMappingDoc = [Select Id,Body from StaticResource where name ='Custom Csv File'];
String hex5digitUPMapStr = EncodingUtil.convertToHex(FiveDigitUPCodeMappingDoc.Body);
System.assertEquals(0, hex5digitUPMapStr.length() & 1);
final Integer bytes5digitUPMap = hex5digitUPMapStr.length() >> 1;
String[] bytes5digitUPStringArr = new String[bytes5digitUPMap];
for(Integer i = 0; i < bytes5digitUPMap; ++i)
bytes5digitUPStringArr[i] = hex5digitUPMapStr.mid(i << 1, 2);
nameFile = EncodingUtil.urlDecode('%' + String.join(bytes5digitUPStringArr, '%'), 'ISO-8859-1');
filelines = nameFile.split('\n');
list<Custom_Business__c> updatecustomlist=new list<Custom_Business__c>();
for (Integer i=1;i<filelines.size();i++) {
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
system.debug('Custom ID is'+inputvalues[1]);
}
}
}
Now, using Custom csv file which is stored in static resource, I need to insert records into Custom Business Object. Can anyone please suggest insert process from above code.