About this question
I have been tasked with processing a large volume of records asynchronously in Salesforce by using a batch apex class. Walk me through the steps that should I take to run this batch class from the developer console.
I have been tasked with processing a large volume of records asynchronously in Salesforce by using a batch apex class. Walk me through the steps that should I take to run this batch class from the developer console.
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Salesforce Expert
Answered on Jun 4, 2024
In the context of Salesforce, here are the steps given:-
Open the developer console
First, launch the developer console from the salesforce setup.
Open Execute Anonymous windows
Now click on the “Debug” in the top menu then select “Open Execute Anonymous window”.
Write batch class invocation code
In the executive anonymous windows, write the code for invoking your batch class.
// Define your batch class
Public class AccountUpdateBatch implements Database.Batchable {
Public Database.QueryLocator start(Database.BatchableContext bc) {
// Your query to fetch records goes here
Return Database.getQueryLocator([SELECT Id, Name FROM Account LIMIT 100]);
}
Public void execute(Database.BatchableContext bc, List scope) {
// Your processing logic goes here
List accountsToUpdate = (List) scope;
For (Account acc : accountsToUpdate) {
// Update logic or any other processing
Acc.Name = acc.Name + ‘ – Updated’;
}
Update accountsToUpdate;
}
Public void finish(Database.BatchableContext bc) {
// Optional finish logic
}
}Execute the code
Now click on “Execute” to run the code. This would start the execution of your batch class.
Monitor batch job
You can monitor the progress of your batch job by just navigating to set-up> monitor>jobs>apex jobs.
Here is an example of Java code that would demonstrate how to run a batch class from the Salesforce developer console. This code would assume you have a batch class named “AccountUpdateBatch” which would update the account records:-
Import com.sforce.async.BatchInfo;
Import com.sforce.async.JobInfo;
Import com.sforce.async.OperationEnum;
Import com.sforce.async.AsyncApiException;
Import com.sforce.async.BulkConnection;
Import com.sforce.soap.partner.PartnerConnection;
Import com.sforce.ws.ConnectorConfig;Public class RunBatchFromConsole {
// Salesforce credentials and configuration
Private static final String USERNAME = “your_username”;
Private static final String PASSWORD = “your_password”;
Private static final String SECURITY_TOKEN = “your_security_token”;
Private static final String AUTH_ENDPOINT = https://login.salesforce.com/services/Soap/u/52.0;
Public static void main(String[] args) { Try {
ConnectorConfig config = new ConnectorConfig();
Config.setUsername(USERNAME);
Config.setPassword(PASSWORD + SECURITY_TOKEN);
Config.setAuthEndpoint(AUTH_ENDPOINT);
PartnerConnection partnerConnection = new PartnerConnection(config);
// Create a Bulk API connection using PartnerConnection
BulkConnection connection = new BulkConnection(config);
// Specify the batch job details
JobInfo job = new JobInfo();
Job.setObject(“Account”); // Object on which batch job will operate
Job.setOperation(OperationEnum.update); // Operation to perform (e.g., update)
Job.setConcurrencyMode(“Parallel”); // Concurrency mode
Job.setExternalIdFieldName(“Id”); // External ID field name if needed
Job.setContentType(“CSV”); // Content type of data (e.g., CSV, XML)
// Create the batch job
Job = connection.createJob(job);
// Specify the batch details
BatchInfo batch = new BatchInfo();
Batch.setJobId(job.getId()); // Associate with the job created above
// Set the CSV data for batch processing (sample CSV data)
String csvData = “Id,Name
001XXXXXXXXXXXX001,Updated Name”;
Byte[] bytes = csvData.getBytes(“UTF-8”);
// Create the batch and upload data
Batch = connection.createBatchFromStream(job, bytes);
// Close the job to start batch processing
Connection.closeJob(job.getId());
// Monitor batch job progress (optional)
// You can check job status and retrieve results as needed
System.out.println(“Batch job submitted successfully!”);
} catch (AsyncApiException | Exception e) {
e.printStackTrace();
}
}
}Here is the same example given in python programming language:-
Import os
Import csv
From simple_salesforce import Salesforce
# Salesforce credentials and configuration
USERNAME = “your_username”
PASSWORD = “your_password”
SECURITY_TOKEN = “your_security_token”
SALESFORCE_INSTANCE = https://login.salesforce.com # For sandbox, use test.salesforce.com
# Initialize Salesforce connection
Sf = Salesforce(username=USERNAME, password=PASSWORD, security_token=SECURITY_TOKEN, instance=SALESFORCE_INSTANCE)
# Define batch data to be processed (sample CSV data)Batch_data = [
{‘Id’: ‘001XXXXXXXXXXXX001’, ‘Name’: ‘Updated Name 1’},
{‘Id’: ‘001XXXXXXXXXXXX002’, ‘Name’: ‘Updated Name 2’},
# Add more records as needed
]# Define the batch job parameters
Batch_job = sf.bulk.Account.update(contentType=’CSV’)
Batch_job.add_csv_data(csv.DictWriter(os.devnull, fieldnames=batch_data[0].keys()).writeheader(), batch_data)
# Submit the batch job
Job_id = batch_job.job(focus=None, operation=’insert’)
# Monitor batch job progress (optional)
# You can check job status and retrieve results as needed
Print(“Batch job submitted successfully!”)Perryedwards Latest answer
Answered on Mar 4, 2025
Thanks for the detailed answers everyone shared. This is exactly the information I was looking for. Let's play block blast unblocked to have great relaxing moments.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Step-by-step Salesforce guides from industry experts
Common Salesforce interview questions, answered
Guides, tips and career advice on Salesforce from JanBask experts.
Salesforce How to Become a Salesforce Administrator in 2027: A Step-by-Step Career Roadmap
Want to become a Salesforce Administrator? Get the complete 2026 roadmap skills, certification, salary & career path. Start your…
Salesforce Salesforce Admin Self Study vs Live Training: How to Choose the Right Path
Compare Salesforce Admin self-study and live training by cost, duration, flexibility, mentorship, and career support. Find the…
Salesforce How a Salesforce Admin Certification Shapes Your Career Growth
Wondering if a salesforce admin certification is worth it? See how it shapes hiring, salary, and long term salesforce admin…
Salesforce Salesforce Admin vs Developer Salary: Which Path Actually Pays More?
Salesforce admin vs developer salary: developers earn 15–25% more. See entry, mid and senior pay, why the gap exists, and how…