+ Start a Discussion
sales@myvarmasales@myvarma 

batchapex to update website value in every account

how to update every account with same website value
Jarosław KołodziejczykJarosław Kołodziejczyk
List<Account> accList = new List<Account>([Select id,Website from Account]);
for(Account acc : accList)
{
   acc.Website = 'YourWebsiteUrl';
}
update accList;
sales@myvarmasales@myvarma
global class batchAccountUpdate implements Database.Batchable<sobject>
{
    
 global Database.QueryLocator start(Database.BatchableContext BC)
  {
   String query='SELECT Id,Website FROM Account';
   return Database.getQueryLocator(query);
  }
    global void execute(Database.BatchableContext BC,List<Account> Website)
     {
         List<Account> accList = new List<Account>([Select id,Website from Account]);
for(Account acc : accList)
{
   acc.Website = 'www.pradeep.com';
}
update accList; 
     }
      global void finish(Database.BatchableContext BC)
     {
       Account a = [Select Id, website
        from Account ];
        
          Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
          String[] toAddresses = new String[] {'pradeep.gunturi@gmail.com'};
         mail.setToAddresses(toAddresses);
      
        
         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
  
     }
}
Arvind KumarArvind Kumar
Hi Sales,

You have written a nice code. Use it, it will work for you.