2

I have written Apex code and VF page for uploading records for my custom object. While uploading the CSV file into system via programatically I am getting the error "Visualforce Error System.Type Exception: Invalid decimal".

Please refer the screenshot for more details. Usually this error is not coming but sometimes it comes. It throws an error in the particular line of (Line no-411) my Apex code " site.Estimated_Value__c = decimal.valueOf(inputsitevalues[9]);".

I have copied the records into other CSV file and then uploaded it works fine. I am not sure whether it is the File format issue or coding issue. Please help me out in this.

Visualforce Error screenshot

  • 1
    My suggestion would be to run the import with debug logs running and see which line of your csv causes the problem; debugging the value for inputsitevalues[9] will help in solving the problem. Something else to try would be to create a method to try and parse the values and throw an exception if an invalid value is found. That way a meaningful error could be shown to the user and detail which line and value is causing the problem. – Richard Durrant Jul 4 '13 at 9:10
  • @RichardDurrant Thank you so much for the reply. I will try write a method to throw an exception if an invalid value is found. One more question, Can we use trim() to resolve this issue. – Arun Jul 4 '13 at 10:04
5

A common problem would be leading white space, try using trim()

site.Estimated_Value__c = decimal.valueOf(inputsitevalues[9].trim());
  • Thanks for the reply. I have used trim(), This is not working for passing null value scenario. If the Estimated value data comes null in spreadsheet then it shows the same error. So I have given one more condition to allow the null value if(inputsitevalues[9] != '') { site.Estimated_Value__c = decimal.valueOf(inputsitevalues[9].trim()); } Now the Invalid decimal error is not coming – Arun Jul 5 '13 at 4:32
  • Cool glad I could help. – Moti Korets Jul 5 '13 at 5:16
1

@Arun I agree with Richard answer. You should try the following to quickly identify the problem.

  1. do a try catch for exception and null and on the catch, print the error record.

  2. Check the excel column and do a right click on the column properties to see if the excel is messing up the data.

  • Thank you for the reply I will try this one and update you. – Arun Jul 5 '13 at 4:15
1

I have encountered this problem and founded that when the number column is the last one in the Excel sheet, the system (salesforce) will throw an error: "invalid integer\decimal". Maybe its because it also reads the and of the line tag from the excel, and this is why it has a problem with identifying it as a integer\decimal. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.