You need to sign in to do that
Don't have an account?
Vivekh88
Insert Datetime using CSV file in VF page
Hi,
I need to insert some records through excel. I have a VF page where i upload the excel file and create records for my custom object. i have a custom field which has Datetime stored. So when i tried to upload the excel with datetime in VF it is going to exception loop. It is not creating records.
This is my class method.
Thanks
Vivek
I need to insert some records through excel. I have a VF page where i upload the excel file and create records for my custom object. i have a custom field which has Datetime stored. So when i tried to upload the excel with datetime in VF it is going to exception loop. It is not creating records.
This is my class method.
public void importCSVFile(){ try{ csvAsString = csvFileBody.toString(); csvFileLines = csvAsString.split('\n'); inputvalues = new String[]{}; for(string st:csvfilelines[0].split(',')) fieldList.add(st); for(Integer i=1;i<csvFileLines.size();i++){ AgendaTopics__c accObj = new AgendaTopics__c(); string[] csvRecordData = csvFileLines[i].split(','); Datetime dt = Datetime.valueOf(csvRecordData[0]); accObj.Time__c = dt; accObj.Estimated_Duration_minutes__c = Decimal.valueOf(csvRecordData[1]); accObj.Topic_Name__c = csvRecordData[2]; accObj.Owner__c = String.valueOf(csvRecordData[3]); acclist.add(accObj); } } catch (Exception e) { ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct'); ApexPages.addMessage(errorMessage); }
Thanks
Vivek
I am passing it as a String.
I am getting the requiered values So after this the values are nor assigned to their corresponding fields I am getting exception in there.
Thanks
Vivek
Now you have two options:
1. Better if you ask me is to force the csv file to contain correct datetime format. Don't know how you create them, but for me it sounds like a better idea.
2. Write a method that will take an input date and format it to correct Salesforce Datetime before it's assign to a field on an object.
Regards
Adrian
So in this code i tried to convert user input date format to 'yyyy-MM-dd hh:mm:ss' but still i am getting the same error.
The method what i gave for converting the datetime format is correct or do i need to change something?
Thanks
Vivek