Sample logic code.
Document doc=[SELECT Body,ContentType,Description,DeveloperName,Name FROM Document WHERE Name = 'Csv File'];
String[] columns=doc.Body.toString().split('\n');
String[] columnNames=columns[0].split(',');
columns.remove(0);
for(String str:columns)
{
Account acc=new Account();
String[] fields=str.split(',');
for(Integer i=0;i<fields.size()-1;i++)
{
acc.put(columnNames[i],fields[i]);
}
lstAccounts.add(acc);
}
Insert lstAccounts;
Apex
,
CSV
,
Salesfroce
Document doc=[SELECT Body,ContentType,Description,DeveloperName,Name FROM Document WHERE Name = 'Csv File'];
String[] columns=doc.Body.toString().split('\n');
String[] columnNames=columns[0].split(',');
columns.remove(0);
for(String str:columns)
{
Account acc=new Account();
String[] fields=str.split(',');
for(Integer i=0;i<fields.size()-1;i++)
{
acc.put(columnNames[i],fields[i]);
}
lstAccounts.add(acc);
}
Insert lstAccounts;
No comments:
Post a Comment