I ve tried this script to create accounts from excel file and it works,but if this file had more fields ,I would have to store their values one by one.Is there a way to do this mapping using something like acc.put(fieldname,value) inside a loop?.
String[] filelines = new String[]{};
List<Account> accstoupload;
StaticResource srObject = [select id,body from StaticResource
Where Name = 'AccountUploadTemplate'];
String contents = srObject.body.toString();
filelines = contents.split('\n');
accstoupload = new List<Account>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Account a = new Account();
a.Name = inputvalues[0];
a.ShippingStreet = inputvalues[1];
a.ShippingCity = inputvalues[2];
a.ShippingState = inputvalues[3];
a.ShippingPostalCode = inputvalues[4];
a.ShippingCountry = inputvalues[5];
accstoupload.add(a);
}
insert accstoupload;
I would have to store their values one by one
- what do you mean by this?