Data Loader VS Batch Apex

dataData, data, and loads of data!!

Would you still prefer to migrate this lot of huge data in the old traditional way by creating the number of excel sheets, matching it, again and again, to avoid any errors, giving strain to your eyes and wasting much of your time? Let’s suppose somehow you managed to import million of records and then end up with inserting few wrong values. Alas, now for sure you have to do it all over again. If we are living in a high-tech world then why would you want to do things manually when it can be done programmatically. Yup, we can insert a lot of data using just a Batch Apex. Though both Data Loader and Batch Apex has its own advantage in their own ways but you have to be judgemental to use it wisely. Let’s throw some light on both of these.

question-markDATA LOADER- What’s this???

Before we waste any time, let’s first understand what Data Loader is. Simple but yet powerful, it’s a Desktop tool to migrate data from two IT systems. It generally focuses more on migrating data in between two different environments. Consider an example where you want to migrate a .csv file from your old legacy system to Salesforce cloud-based system, this can easily be done via Data Loader.

dataloader-icon

scenarioOther Use Case Scenario:

  • Want to have a daily backup of your customer records.
  • Importing records of emails that you want to update for lead comparison.
  • Importing a report file that is been generated in third party marketing automation tool that you want to link with Salesforce accounts.

functionHow It Function??

When you import data, Data Loader first reads it, then extracts it and lastly loads data from CSV files or database connections. See operations below:

 

Salesforce-Data-loader-install

 

addvantageDATA LOADER- Advantage

Data loader has too many advantages in its own way:

  • The first and the foremost advantage is its automation process for complete data migration & yes! it’s hassle free.
  • It helps you insert, export, update and delete data.
  • One can perform DML Operations on up to 5 million records.
  • It is an easy-to-use GUI-based interface.
  • Drag and drop field mapping is one of its features.
  • Detailed files showing success and error messages make it more easy to use.
  • It supports Windows or Mac.

question-markBATCH APEX- What’s this???

Large sets of data is not a piece of cake for Data Loader in any way, It’s when Batch Apex comes into the scene. It generally focuses on processing bulk data within SFDC. It is easy to use with large volume set of data for migration. What one needs to do is just include your custom logic on the data for which you want to have data manipulations in bulk. It does not care about the external environment. It has a CLI interface that must be implemented by a developer for batch processing the data files.

scenarioUse Case Scenario:

  • We can use it if suppose a person wants to create multiple opportunities daily.
  • Batch to run daily and bring all the leads having no phone number and then sending emails to the user accordingly.

Sample Code

global class CreateDaily5Oppo implements Database.Batchable<sObject> {

global Database.QueryLocator start(Database.BatchableContext bc){

return Database.getQueryLocator([select id from Account limit 5]);

}

global void execute(Database.BatchableContext bc,list<Account> acc){

integer i=0;

list<Opportunity> oppoList=new list<Opportunity>();

for(Account ac:acc){

Opportunity op=new Opportunity();

op.Name=’Batch’+i;

op.CloseDate=date.Today();

op.StageName=’Closed lost’;

op.AccountId=ac.Id;

i++;

oppoList.add(op);

}

Database.insert(oppoList);

}

global void finish(Database.BatchableContext bc){

system.debug(‘Finished’);

}

}

 

functionHow It Functions??

To understand how Batch works let’s divide it into steps:

  • It fetches up all the records on which you want to perform the field update.
  • Once this is done, it divides data into batch or list of 200 record sets.
  • Now the operation is performed on every 200 records separately.
  • To invoke batch jobs one needs to call it via apex.

addvantageBATCH APEX- Advantage

Batch Apex has following advantages:

  • They can be scheduled to run at specific times using Apex Scheduler.
  • It provides the strong level of flexibility.
  • Helps to process huge data records in batches.
  • It has higher governor limits.

This was all about the difference that lies in “Data Loader” and “Batch Apex”. It depends totally on you to choose what to use by keeping in mind the size of your data and its use in the longer run.

Happy Coding!!…


Author: AJ

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *

ajay-certified-pic1

Interested In Knowing More...

Hi! I am Ajay Dubedi, Salesforce 5x Certified Along With JAVA Programmer Certification And JAVA Web Component Developer Certification. I am An Expert In Salesforce CRM Solutions With In-depth 7 Yrs Of Hands On Experience In Variety Of Salesforce Integrations, Customizations & App Development.

Let's Get In Touch & Start Working On Something Cool!

Hey! great, thank mate for sharing your email, I am pretty excited to know you visited my website & shown interest in my content. Just keep an eye on your inbox for my emails :)