You need to sign in to do that
Don't have an account?
Rolando Esteves
Uploading CSV file to custom object on MAC
Hi ! Thank You in Advance!
I have a custom development and it works fine for windows users. I would like to be able to process csv files from a mac enviroment. Im using BLOB in order to to process Windows csv files. Any help would be greatly appriciated!
Here is my code :
public with sharing class UploadRecordUsingCSV { public UploadRecordUsingCSV(ApexPages.StandardController controller) { } // I wish to parse a file from MAC here public Blob FileRecords{get;set;} public String[] LineNo= new String[]{}; public List<CSV_UPLOAD_HISTORY__c> AllUnit; Public Pagereference UploadFile() { integer FileRow = 1; String oppID = System.currentPageReference().getParameters().get('id'); String oppName = [SELECT A.NAME FROM OPPORTUNITY A WHERE A.ID =:oppID].Name; Opportunity opp = [SELECT A.NAME FROM OPPORTUNITY A WHERE A.ID =:oppID]; OPPDULHISTORY__c btchHist = new OPPDULHISTORY__c (); btchHist.Name = oppName + '-' + String.valueOf(Date.Today()); insert btchHist; system.debug('Enter'); try{ String FileData = FileRecords.toString(); LineNo = FileData.split('\n'); AllUnit = new List<CSV_UPLOAD_HISTORY__c>(); system.debug('Entered****'+ AllUnit); for(Integer i=1;i<LineNo.size();i++) { CSV_UPLOAD_HISTORY__c cuh= new CSV_UPLOAD_HISTORY__c(); String[] ActualData=new String[]{}; ActualData=LineNo[i].split(','); // Parsin BLOB and STRINGS cuh.Name = oppID + ActualData[0] ; cuh.Batch_History__c = btchHist.Id; cuh.OpportunityID__c = oppID; cuh.Part_Number__c = ActualData[0]; cuh.Qty__c = double.valueOf(ActualData[1]); cuh.VUC__c = double.valueOf(ActualData[2]); cuh.Discount__c = double.valueof(ActualData[3]); cuh.Gross_Margin__c = double.valueof(ActualData[4]); cuh.ImportTax__c = double.valueof(ActualData[5]); cuh.Tax__c = ActualData[6]; cuh.Vendor__c = ActualData[7]; cuh.Status__c = 'Succes!'; cuh.File_Row__c = FileRow++; AllUnit.add(cuh); } }catch(Exception e){system.debug('Please select a file!');} insert AllUnit; // PageReference curPage = new ApexPages.StandardController(opp).view(); // curPage.setRedirect(true); // return curPage; return Null; } }
Hi Guys,
All though I did not discovered how to process csv files from MAC on apex. The work around we are using is that people save the file in office for mac of type: CSV(Windows Comma Separated Values)
REG
All Answers
Hi Guys,
All though I did not discovered how to process csv files from MAC on apex. The work around we are using is that people save the file in office for mac of type: CSV(Windows Comma Separated Values)
REG
Hi Rolando,
I am really sorry to bother you, but I am interested in your code. I'm looking to do the same thing for my Org as I want to be able to
allow users to upload a csv to update a specific custom object (which they have write access to).
However, as I am new to APEX, appreciate if you could explain the first part of your code and what it does.