我在使用顶点时遇到了问题:我创建了一个对话框,允许我加载CSV文件。但是,当我加载它时,它返回以下错误消息:
09:17:41:021 VARIABLE_ASSIGNMENT [19] | e |“ common.apex.runtime.impl.ExecutionException:BLOB不是有效的UTF-8字符串” | 0x72d1bdb2
在CSV文件中,有诸如“-”和“ _”之类的符号。我怀疑这就是加载失败的原因。
这是我的代码:
public class ImportExcel {
public String fileName {get; set;}
public Blob contentFile {get; set;}
public String[] csvFileLines {get; set;}
public List<String> acclist {get; set;}
public String[] data {get; set;}
public ImportExcel() {
csvFileLines = new String[]{};
acclist = New List<String>();
}
public void readFile() {
try {
fileName = contentFile.toString();
system.debug(fileName);
} catch (Exception e) {
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Please upload a valid CSV document');
ApexPages.addMessage(myMsg);
return;
}
csvFileLines=fileName.split('\n');
for (Integer i = 1; i < csvFileLines.size(); i++) {
data = csvFileLines[i].split(',');
acclist.add(csvFileLines[i]);
}
}
}