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
Ankit SinghalAnkit Singhal 

How to pass a List of Task Records to Batch class

i want to pass a list of task records 

say 

List<Task> Tasklist 

to the batch class for insertion.

How to call Batch class for this list of tasks.

LVSLVS

Why do you want to insert in batches? What will trigger this apex? Can you add some more detail of your requirement?

 

Often, the community is able to provide better solutions to your requirements than trying to fix a problem while doing it your way so its always better to tell us what problem you're trying to solve...

 

~LVS

Ankit SinghalAnkit Singhal

Hi,

 

I want to do it in batch because task records in list are more than 50k.

So this is a client reuirement.

 

i have a Utility class SMPDAO

 

 

say

 

public Class SMPDAO

{

 

public static TaskReturn(Arg1,Arg2)

{

 

if (Tasklist.size()>50000)

//then need to use batch to insert Task records

else

insert Tasklist; 

 

 

Now since i have never used batch Class,can u plz guide me how to pass this list as Arguement to Batch Class.

tHanks in Advance.

Mayank_JoshiMayank_Joshi

Can Try Below:

List<task> Lst_Task = [Select Id from Task Limit 50000]; 

 

I would suggest to use WHERE clause to filter out desired records in SOQL .So that it wil not give query time out error . If there are large amount of data . 

 

 

 

 

LVSLVS

Note that any set of records queried from the start() method of a batch class is automatically broken into batches and the execute() method is called for each batch

 

Please refer the Apex Batch documentation here for more detail.

 

Since you are working with a large data set, I recommend you read this as well: http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_VLSQ.htm

vishal@forcevishal@force

Hi Ankit,

 

In a Batch class, we pass the set of records that are to be processed, in your case there are no records (they have not yet been inserted). So I don't think this is the correct solution for your requirement.

 

How is the TaskList getting filled in your code?

TrinayTrinay

Hi Ankit,

 

 I hope you can done this insert process without use of a Batch Process, by iterating your records over a for loop.

 

and if you want to use a Batch Apex process for your task. Refer the following link:

 

http://salesforcesource.blogspot.in/2010/02/utilizing-power-of-batch-apex-and-async.html 

 

http://blogs.developerforce.com/systems-integrator/2009/05/batch-apex-a-powerful-new-functionality-in-summer-09.html

 

These links are have good information about Batch Process and it also have example code for Batch Process  .

 

I hope this will helpful to you.