I am inserting records using CSV file. While adding file without any deletion its working perfectly fine.
In my code i am checking if the value is equal to null giving error. So when I delete values from the csv file (deleting values not rows) It is still assuming it has values and giving error "Error uploading" (added by me in logic).
How to overcome this issue ?
Class :
for (Integer i = 1; i < filelines.size(); i++) {
String[] inputvaluesFile = new String[] {};
inputvaluesFile = filelines[i].split(',');
productList__c prod = new productList__c();
if (inputvaluesFile[0] != '') {
prod.Number__c = inputvaluesFile[0];
}
prod.Note__c = inputvaluesFile[1];
prod.Description__c = inputvaluesFile[2];
if (inputvaluesFile[3] != '') {
prod.unit__c = decimal.valueOf(inputvaluesFile[3]);
}
if (inputvaluesFile[4] != '') {
prod.Price__c = decimal.valueOf(inputvaluesFile[4]);
}
// if i delete some values in csv its still assuming it has record instead of treating as end of file and giving below error
if (prod.Number__c != null && prod.Note__c != null && prod.AccountId != null && prod.Price__c != null) {
newList.add(prod);
}
else ApexPages.addmessage(new ApexPages.Message(ApexPages.severity.Error, 'Error uploading the product'));