Thursday 8 August 2013

Batch Apex & CSV Parsing - I am Lovin'it !!


Situation :

I have a CSV File with 3 Fields Lead ID , Yes|No Field and Operator Name.
Without Using Data Loader I need my Data Entry Team to Upload this File  and Leads get updates with these values in the respective fields.



Solution :

Perhaps , Data Loader is the Mirror Cracking Solution. But you cannot get all the happiness at once.

Making the Data Entry team familiar with Data Loader and expecting that they will do correct is like expecting a lion not to eat you all because you are a Vegetarian.

So , Clear Cut My Process was turned up to Batch Apex CSV Parsing . Yes ! You Heard It Correct Batch Apex CSV Parsing .

So , I went to my Manager with this serving on Plate...

I will create a Visualforce Page with a Browse Button.
When a CSV File with Correct Format is Uploaded from there.It will call an controller which will call the Batch Process . The Batch will call a class which will insert records from the values which it gets from another class. Make Sense ?

His words "Sounds Delicious !! "

So , I started upon it .. Here are the ingredients

1.  Page -- BatchUpdateLeads

/* This will be the Visualforce Page with the Browse Button. /*

2. ctrlUpdateallrecFromCSV

/* This will be the Extension which will be called from the Page. /*

3. BatchProcessor

/* Called from the Extension, This is the Actual Batch Process. /*

4. BatchSObjectFeeder

/* This will be an Input for the Batch Apex in its Start Method. /*

5. ctrlAdddataFromCSV

/* This will be the called from the Batch Apex. "InsertValues"  Method will be called. Also , This is the class responsible for Saving the Records in Salesforce. /*
6. clsAdddataFromCSV

/* This is the Class called from ctrlAdddataFromCSV , The main process of this is to parse the excel sheet  . /*



Get the Code from Here ..
Disclaimer : This is a chain of classes as I respect OOP Concepts.


Hope it works well for you all !

Happy Batch Update !! :-)