I'm trying to convert a number in a CSV file column into a value that I can save in a custom object field. My custom object has a Geocode field type, which is comprised of two individual fields (Geoloc__Latitude__s and Geoloc__Longitude__s). When I try to convert the String to an Integer, I get the above error.
Public void readCsvFile() {
if(csvData != null) {
csvStringFileData = csvData.toString();
csvFileLines = csvStringFileData.split('\n');
for(string st:csvFilelines[0].split(','))
fieldList.add(st);
for(Integer i=1;i<csvFilelines.size();i++) {
Client_Site__c clientLocation = new Client_Site__c();
string[] csvRecordData = csvfilelines[i].split(',');
clientLocation.SITE_NAME__c = csvRecordData[0];
clientLocation.ADDRESS__c = csvRecordData[1];
clientLocation.CITY__c = csvRecordData[2];
clientLocation.STATE__c = csvRecordData[3];
clientLocation.ZIP__c = csvRecordData[4];
clientLocation.FRANCHISEE__c = csvRecordData[5];
clientLocation.SITE_ID__c = csvRecordData[6];
clientLocation.SITE_OWNER__c = csvRecordData[7];
clientLocation.Geoloc__Latitude__s = Integer.valueOf(csvRecordData[8]);
clientLocation.Geoloc__Longitude__s = Integer.valueOf(csvRecordData[9]);
clientLocation.RequestForProposal__c = rfpId;
clientLocationList.add(clientLocation);
}
}
}
How do I convert the String to something I can save in a Geocode field?
Best Answer
Try changing
integer.valueof(csvRecordData[8]);
todecimal.valueof(csvRecordData[8]);