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 !! :-)


9 comments:

  1. Dudewhere can I see the code for this ?:

    ReplyDelete
  2. Check the GitHub Link I posted. You can get the code from there.

    ReplyDelete
  3. Hi.. I like this post... But, Im not able to find the class 'batchprocessor'. Would you be able to point it to me?

    ReplyDelete
  4. Thanks Gautam... But whre is the batchprocessor class ?

    ReplyDelete
  5. @Dan Levin ,@ Anonymous Thanks for reminding me about what I missed. With your help , i was able to overcome the flaw which was there . Please check the GitHub Repository Again. I have updated the Batch Class . Hope this works for you well :)

    ReplyDelete
  6. bro
    here you miss the iterator process class for this "BatchSObjectFeeder". beacuse this batch is "iterable"

    ReplyDelete
  7. @Balakrishna Reddy: can you please elaborate on your post, since my code is stuck at this point

    ReplyDelete
  8. Hey, you have my life..I'm new to salesforce and had just a day to achieve something like this..

    ReplyDelete
  9. how to use apex batch class for import csv file

    ReplyDelete