function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ArunaAruna 

please help out me doing this task importing a excel sheet using apex and vf

Hi

 

 I have a  requirement that i need to  create a tool that import the excel sheet into salesforce object.

 

you may have doubt that why can't  you use Apex data loader  or Excelconnector  ect ,

 

but this is for the business users they don't be having any knowledge  about  dataloader and excelconnector.

 

they  need a button when they click on that  button  excel sheet should be imported into  salesforce object witn fiedl mapping .

 

please please help out me doing this task.

 

it will be very help full if any one give me an idea how to do and with sample code.

 

or is there any other tool which can be used by the business users to load excel sheet.

 

Thank you

Virendra NarukaVirendra Naruka

You can use java utility for that .. using SFDC webservices api

 

ArunaAruna

can you please send me  how to proceed with this and a sample code .

 

 

Thank you

 

 

 

Virendra NarukaVirendra Naruka

 Hi ,

 

you can use this type of tag on VF page

 

<apex:inputFile value="{!contentFile}" filename="{!nameFile}" />

 

contentFile will be property of blob type.

 

you can parse by contentFile.tostring() . It will give you whole string of CSV/excel file.

then use split method of Apex string object .

ArunaAruna

 I am new to this i will be very thank full to you  if you send me sample code or example of this type., please don't mind i am asking all this .

 

Thank you

 

Virendra NarukaVirendra Naruka

HI 

 

Create a VF Page with a controller 

on vf page use Apex tag like below 

 

<apex:inputFile value="{!contentFile}" filename="{!nameFile}" />

 

 

Create a command button on VF Page . it will call your Contoller's  Function 

like : <apex:commandButton  value="Upload File" action="{!parseContentType}"/> 

 

 

On controller Create a Property like 

contentFile will be property of blob type.

Public blob contentFile{get;set;}

 

public pageReference  parseContentType(){

   String  contents = contentFile.toString();

   /*

    Here you can write the code to Split the String and get Your records

   After parsing create new Object and assign the value to object and insert

  */

}