Activity Forums Salesforce® Discussions How to create records of any selected object using Salesforce Batch Apex Class?

  • How to create records of any selected object using Salesforce Batch Apex Class?

  • Namrata

    Member
    October 4, 2018 at 1:17 pm

    I wanted to create n number of records of any selected object using Batch Apex class where n is input by user .

     

  • Rajan

    Member
    July 30, 2019 at 10:55 am

    Hi Namrata

    global class batchForUserInput implements Database.Batchable<sObject> {
    global batchForUserInput(string inputUser){
    this.inputUser = inputUser;
    }
    global Database.QueryLocator start(Database.BatchableContext BC) {
    String query = 'SELECT Id,Name FROM inputUser';
    return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<sObject> scope) {
    for(sObject a : scope)
    {
    a.Name = a.Name + 'Updated';
    }
    update scope;
    }

    global void finish(Database.BatchableContext BC) {
    }
    }

Viewing 1 - 2 of 2 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos