Activity Forums Salesforce® Discussions How to update multiple sObjects field in a Salesforce Apex batch class?

  • Vikas Kumar

    Member
    January 16, 2017 at 7:19 am

    Hi sushant,

    you can do something like this

    global class TestBatch implements Database.Batchable<sobject>{
    global String query;
    global String field;
    global String value;
    global List<id>allObjIds ;
    global TestBatch(List<id>allObjectIds){
    allObjIds=allObjectIds;
    field='Name';
    value='ModSEARCHAccount';
    }
    global Database.QueryLocator Start(Database.BatchableContext BC){
    query='SELECT Id,Name FROM Account WHERE Id in:allObjIds';
    return Database.getQueryLocator(query);
    }
    global void execute (Database.BatchableContext BC,List<Sobject>scope){
    for(Account obj:scope){

    obj.put(field,value);

    }
    update scope;
    }
    global void finish (Database.BatchableContext BC){

    //call another batch from here to to update another object says lead or opportunity
    }
    }

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos

Free 5 Day Salesforce Challenge!

Video in

To access the signup form head over to www.talentstacker.com/Salesforce TalentStacker Podcast Salesforce Episode: https://talentstacker.libsyn.com/how-to-earn-60k-100k-a-year-within-6-months-without-a-college-degree-say-what-salesforce-career-development-path-with-bradley-rice Do you already have a job as a Salesforce Professional and…