function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lokesh Rayapati4Lokesh Rayapati4 

By using batch class fields need to be updated daily with todays date + account name for all account in the org

Hi,

I'm new to developement. I want to do batch class by using to build a text field on account named "Todays execution".This fields needs to be updated daily wth todays date + account name for all the account in the org.

Thanks in advance
 
Best Answer chosen by Lokesh Rayapati4
CharuDuttCharuDutt
Hii Lokesh
Try Below Code
public class AccountProcessor implements Database.Batchable<sObject> {
    public Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator('SELECT id,Name,Todays_Execution__c FROM Account');
    }
    public void execute(Database.BatchableContext bc, List<Account> records){
        for(Account Acc : records){
           Acc.Todays_Execution__c = System.Today()+ '' +Acc.Name;
        }
        update records;
    }
    public void finish(Database.BatchableContext bc){
        Id job = bc.getJobId();
    }
Please Mark It As Best Answer If  It Helps
Thank You!

 

All Answers

CharuDuttCharuDutt
Hii Lokesh
Try Below Code
public class AccountProcessor implements Database.Batchable<sObject> {
    public Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator('SELECT id,Name,Todays_Execution__c FROM Account');
    }
    public void execute(Database.BatchableContext bc, List<Account> records){
        for(Account Acc : records){
           Acc.Todays_Execution__c = System.Today()+ '' +Acc.Name;
        }
        update records;
    }
    public void finish(Database.BatchableContext bc){
        Id job = bc.getJobId();
    }
Please Mark It As Best Answer If  It Helps
Thank You!

 
This was selected as the best answer
Suraj Tripathi 47Suraj Tripathi 47

Hi,

public class AccountData implements Database.Batchable<sObject> {
	 List<Account> accountList{get;set;}
	 
	 public AccountData(){
	 accountList=[SELECT id,Name,yourDate__c FROM Account];
	 }
    public Database.QueryLocator start(Database.BatchableContext bc) {
        return  accountList;
    }
    public void execute(Database.BatchableContext bc, List<Account> AccList){
        for(Account Ac : AccList){
           Ac.yourDate__c = Date.Today()+ ' _ ' +Ac.Name;
        }
        update AccList;
    }
    public void finish(Database.BatchableContext bc){
        system.debug('accountList'+accountList);
    }

Thanks
Lokesh Rayapati4Lokesh Rayapati4

Please can you help with Schedule class for this
Here i created this and scheduled in org

global class Scheduledforbatchapex2 implements Schedulable {
    global void execute(SchedulableContext sc){
        AccountProcessor ap = new AccountProcessor();
        database.executebatch(ap);
    }
    
}
CharuDuttCharuDutt
Hii Lokesh
Your Schedule Class Is Correct What Is The Error Coming Please Explain   
Lokesh Rayapati4Lokesh Rayapati4
Hi Charudutt
I wrote the above schedule and didnt know logic to schedule for daily updation of date and acc name. I actually scheduled from org by going to apex classes. Thank you so much for your response.It's really helpful.