public class MacNCController{
String[] filelines = new String[]{};
public String documentName {get;set;}
public Blob csvFileBody{get;set;}
public String[] contactDataLines {get;set;}
public boolean readSuccess {get;set;}
public List<String> lstFieldNames{get;set;}
String contactDataAsString;
String s;
public String[] csvFieldNames;
public string nameFile{get;set;}
Contact conObj;
public List <Contact> lstContacts {get;set;}
String fieldValue;
Integer fieldNumber;
Map <String, Integer> fieldNumberMap = new Map < String, Integer > ();
public MacNCController()
{
documentName = '';
readSuccess = FALSE;
contactDataLines = new String[] {};
lstFieldNames = new List<String>();
system.debug('**** csvFileBody ****'+csvFileBody);
}
public void actionMethod(){
csvFieldNames =new String[] {};
system.debug('**** csvFileBody ****'+csvFileBody);
//csvFileBody=deletedocument[0].body;
system.debug('**** csvFileBody ****'+csvFileBody);
nameFile=csvFileBody.toString();
filelines = nameFile.split('\n');
csvFieldNames =filelines[0].split(',');
System.debug('**** csvFieldNames ****'+csvFieldNames );
//system.debug('** accstoupload **'+accstoupload);
//Database.insert(accstoupload,false);
SObjectType objectToken = Schema.getGlobalDescribe().get('Contact');
Map < String, Schema.SObjectField > mapFieldList = objectToken.getDescribe().fields.getMap();
system.debug('**** mapFieldList **'+mapFieldList );
for(String CsvFied:csvFieldNames ){
system.debug('*** CsvFied ***'+CsvFied);
for (Schema.SObjectField field: mapFieldList.values()) {
Schema.DescribeFieldResult fieldResult = field.getDescribe();
if(fieldResult.isCreateable() == true){
if (fieldResult.getName() == CsvFied) {
system.debug('*** fieldResult.getName() ***'+fieldResult.getName());
system.debug('*** both matched ***');
}else
system.debug('*** not matched ****');
}
}
}
}
}
Upload CSV file
Here is requirement details,from csv iam passing contact data(with field names and values)iam reading the column names of csv and using schema checking in Standard object whether any object fields name is same or not,if it is creatable.now field from csv and field in Standard object are same,i did till here,now i want to create the record to the matched fields.how can i achieve,thanks in advance