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
hari0853701703454959hari0853701703454959 

Update the all fields for Task using batch apex

Hi,
  How to update the  all fields for task and  using Batchapex....
thanks,
hari
Vinit_KumarVinit_Kumar
Have you created a batcahble class in salesforce,if not Try below sample code :-

global class batchTaskUpdate implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        //query on Task
        String query = 'SELECT ActivityDate,Status FROM Task';
        return Database.getQueryLocator(query);
    }
   
    global void execute(Database.BatchableContext BC, List<Task> scope)
    {
         for(Task a : scope)
         {   
             //Updating Task status to completed
             a.Status = 'Completed';            
         }
         update scope;
    }   
    global void finish(Database.BatchableContext BC)
    {
    }
}

Then,go to developer console and run below code to execute the batch :-

batchTaskUpdate b = new batchTaskUpdate ();
Datbase.executeBatch(b);

If this helps,please mark this as best answer to help others :)
hari0853701703454959hari0853701703454959
hi, I have another requirement i.e.,Status="completed" the task is come to activity history that *count* display on* Lead record page*..If iam update the fields in Task by using *Batchapex *the update fields are alsoaffect on lead record page... Thanks, hari Thanks&Regards *Hareesh.I*
Vinit_KumarVinit_Kumar
Have you created something or are you expecting someone else to write the code for you ??

This forum is to help people when they are stuck somewhere,not to implement scenario for them.

I would suggest to go through the sample code and update it as per your requirement, if you are stuck somewhere we  can take a look !!
Vinit_KumarVinit_Kumar
This is VF page controller and your post says you need help about Batch classes.

These are 2 different thigs.Try to elaborate as what you want to do ??
hari0853701703454959hari0853701703454959
hi, *how to write the test class for below coding* public class IGT_ServerEditController { ApexPages.StandardController con; public Boolean Show{get;set;} public Boolean hide{get;set;} public Id serverId{get;set;} public IGT_ServerEditController(ApexPages.StandardController controller) { con=controller; Show=true; hide=false; serverId=ApexPages.currentPage().getParameters().get('Id'); } public IGT_ServerEditController() { serverId=ApexPages.currentPage().getParameters().get('Id'); } public PageReference saveServer() { con.save(); Show=false; hide=true; system.debug('test save.........'); return null; } public PageReference Redirect() { String objName =serverId.getSObjectType().getDescribe().getName(); if(objName=='BMCServiceDesk__BMC_ComputerSystem__c') { PageReference BMCcomSys=new PageReference ('/apex/IGT_ServerEditPage?id='+serverId); BMCcomSys.setRedirect(true); return BMCcomSys; } else { PageReference IGTcomSys=new PageReference ('/apex/IGT_ServerRecordEditPage?id='+serverId); IGTcomSys.setRedirect(true); return IGTcomSys; } return null; } } Thanks&Regards *Hareesh.I*
Pavan Kumar KajaPavan Kumar Kaja
Paste the code properly.