You need to sign in to do that
Don't have an account?

Error on Insert records with CSV file
Hello
I'm using a code I found to insert record to SF via csv file (here is the blog I used the general template: http://www.forcetree.com/2010/08/read-and-insert-records-from-csv-file.html)
I've create a custom object so that users will be able to import log records using excel. I've encountered an issue: all the fields that I created are Number data type and in the original file, the data types are String.
I'm getting an error message: "Error: Compile Error: Illegal assignment from String to Decimal at line 19 column 13"
public class FileUploader
{
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<Log_File__c> logstoupload;
public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
logstoupload = new List<Log_File__c>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Log_File__c a = new Log_File__c();
a.Number_Of_Hosts__c = inputvalues[0];
a.Number_Of_VMs__c = inputvalues[1];
a.Number_Of_Centers__c = inputvalues[2];
logstoupload.add(a);
}
try{
insert logstoupload;
}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
return null;
}
public List<Log_File__c> getuploadedAccounts()
{
if (logstoupload!= NULL)
if (logstoupload.size() > 0)
return logstoupload;
else
return null;
else
return null;
}
}
Can someone can assist in solving this? this tool is something that I need desperately...(users need to upload files and they can't use the starndard import custom object funcionality - a big permission issue)
Also, does anyone knows how to start writing a test class for this?
Thanks in Advance!
Itay
Hi,
I think need to be converted.
This is what I did, thanks!
I have another problem: when importing the template, i'm getting the following error:
BLOB is not a valid UTF-8 string
my visualforce page is as follows:
now i'm getting:
Invalid integer: 35
Error is in expression '{!ReadFile}' in component <apex:page> in page upload_logs
One of the values in the excel is 35... Any help? apex class is as follows:
Almost there...I'm trying to redirect the page (after inserting the CSV) to a case: I've created a lookup between the custom object "Log File" and Case, and in the class i've added the row
a.Case__c = ApexPages.currentPage().getParameters().get('id'); to capture the case ID and link the logs to the case when uploading. Is it the correct way to do so??
The only thing left for me is redirecting to the case record... any help?
Maybe im wrong with the explanation but for sure do not put the number data in the last column when trying to read a csv file in salesforce.
https://www.codengine.in/2019/06/blob-is-not-a-valid-utf-8-string-salesforce-apex.html