You need to sign in to do that
Don't have an account?
Salesforce Dev199
Pass 10000 records from apex class to batch apex
How can we pass 10000 records from Apex class to batch class and update 10000 records of Sobect type lead & contact Opps.
I'm trying to change the owner of 10000 records. so I've created a lwc, where I'll take the user from 1st dropdown of which user record will need to transfer, 2nd drop down will be to which user it should transfer.
Let me know how i can achieve this
I'm trying to change the owner of 10000 records. so I've created a lwc, where I'll take the user from 1st dropdown of which user record will need to transfer, 2nd drop down will be to which user it should transfer.
Let me know how i can achieve this
* Use the apex class to initiate the batch class and set params.
* Inside the batch handle the logic.
The below example will help
public class MyBatchClass implements Database.Batchable<SObject> {
private String user1;
private String user2;
public MyBatchClass(String param1, String param2) {
this.user1 = param1;
this.user2 = param2;
}
public Database.QueryLocator start(Database.BatchableContext batchableContext) {
String query = 'SELECT Id, Name FROM Opportunity WHERE ownerid in:user1';
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext batchableContext, List<SObject> scope) {
// transfer the record to 2nd user
}
public void finish(Database.BatchableContext batchableContext) {
// Your logic after the batch execution is complete
}
}
public class apexClass {
public static void callBatchWithParams() {
String myParam1 = 1st user's id;
String myParam2 = 2nd user's id;
MyBatchClass batchInstance = new MyBatchClass(myParam1, myParam2);
Integer batchSize = 200;
// Start the batch job
Database.executeBatch(batchInstance, batchSize);
}
}
To update 10,000 records of different object types (Lead, Contact, Opportunity) and transfer ownership from one user to another, you can follow these steps:
Create a Lightning Web Component (LWC) that allows users to select the source user and target user to transfer ownership.
Use Apex to query the records that need to be updated. Depending on your use case, you might need to query Leads, Contacts, and Opportunities separately based on the selected users.
Pass the queried records to a Batch Apex class. To do this, you can create a custom Apex class that implements the Database.Batchable interface. The Batch Apex class will process the records in batches, allowing you to handle large volumes of data efficiently.
Here's a general outline of how to proceed:
LWC HTML (transferOwnershipLWC.html): LWC JavaScript (transferOwnershipLWC.js): Apex (TransferOwnershipController.cls):
Hope this helps !
Thank you.
Thank you for your response, but in my case, there are multiple subjects I want to transfer, (lead contact oppo and task event ), so can we query in the start of batch?