You need to sign in to do that
Don't have an account?
LIM AI KHOON
A function to let user mass update record
Hi, I want to create a function where users can mass update their existing data by uploading the CSV file. This is the code. But I get an error.
I get an error in this line:
If we want to have a mass upload record from CSV files to salesforce, we can use
public class FileUpdate { public string nameFile{get;set;} public Blob contentFile{get;set;} String[] filelines = new String[]{}; List<Account> accstoupload; /***This function reads the CSV file and inserts records into the Account object. ***/ public Pagereference ReadFile() { try{ //Convert the uploaded file which is in BLOB format into a string nameFile =blobToString( contentFile,'ISO-8859-1'); //Now sepatate every row of the excel file filelines = nameFile.split('\n'); //Iterate through every line and create a Account record for each row 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.update(a); } } catch(Exception e){ ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured reading the CSV file'+e.getMessage()); ApexPages.addMessage(errormsg); } //Finally, insert the collected records try{ insert accstoupload; } catch (Exception e) { ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured inserting the records'+e.getMessage()); ApexPages.addMessage(errormsg); } return null; } /**** This function sends back to the visualforce page the list of account records that were inserted ****/ public List<Account> getuploadedAccounts() { if (accstoupload!= NULL) if (accstoupload.size() > 0) return accstoupload; else return null; else return null; } public static String blobToString(Blob input, String inCharset){ String hex = EncodingUtil.convertToHex(input); System.assertEquals(0, hex.length() & 1); final Integer bytesCount = hex.length() >> 1; String[] bytes = new String[bytesCount]; for(Integer i = 0; i < bytesCount; ++i) bytes[i] = hex.mid(i << 1, 2); return EncodingUtil.urlDecode('%' + String.join(bytes, '%'), inCharset); } }This is the error
Method does not exist or incorrect signature: void update(Account) from the type List<Account>
I get an error in this line:
accstoupload.update(a);May I know how to debug this?
If we want to have a mass upload record from CSV files to salesforce, we can use
accstoupload.add(a);But why I cannot change from add to update when I want to update the existing records?
ListOfRecord.update(a) in your case it is accstoupload.update(a)
if we want to update a record than we add it to list first ListOfRecord.add(a) and then use DMl Update .
Update ListOfRecord
I hope I made it clear.
Thanks!
All Answers
When you are writing this accstoupload.add(a); you are just adding one account record to the list. Its not getting inserted/ uploaded from here.
You have used insert accstoupload; to insert/upload records.
So this accstoupload.update(a) in incorrect .
Thanks!
this is the error Method does not exist or incorrect signature: void update(Account) from the type List<Account>
ListOfRecord.update(a) in your case it is accstoupload.update(a)
if we want to update a record than we add it to list first ListOfRecord.add(a) and then use DMl Update .
Update ListOfRecord
I hope I made it clear.
Thanks!