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
jaxdmasterjaxdmaster 

calling batch from trigger

Hi All,

 

I have a record R1 in which there is a field called description which needs to updated from a value computed  from web-service call. To accomplish this I created an apex batch in which I pass R1 record Id. There in batch I call web-service and parse out xml and get the desire value. Now in execute method after all computations I do following:

 

R1.desc = value;

update R1;

 

But this throws an error to avoid this I've used try catch block. Everthing fine but value doesnt get updated in R1. What is I am missing?

 

Thanks

Starz26Starz26

You are missing some code snippets in your post that would help us see what you may be missing....

jaxdmasterjaxdmaster

Sorry guys I was about to post my code but fortunately I found solution to my problem. Thanks all

IspitaIspita

To start a batch job, you need to create an instance of your  batch class and call the executeBatch method.

Refer to the code snippet below:-


MyBatchTest b = new MyBatchTest( ... ) ;

ID myBatchJobID = Database.executeBatch(b) ;

 

When you call executeBatch on your instance, the system enqueues the job for processing and returns an ID. When the system is ready to execute the job, it calls the start method and then calls the executeBatch method for chunks of 200 records.

 

For further clarity refer to the following link:-

 

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

 

Hope this helps....

UVUV

Suppose "Sample" is your batch class and you want to execute it from the trigger then-

1- Define a public method in your batch job.for example

public void RunBatch()

{

        database.executeBatch(new Sample());// pass the optional parameters if you want to pass

}

 

2- call this public method from your trigger like-

new Sample().RunBatch();

 

Or

 

you can directly call the batch apex from your trigger in this way-

        database.executeBatch(new Sample());// pass the optional parameters if you want to pass

 

Furthermore, if you want to call the batch apex fromt he schedulable class then use database.executeBatch().

See this complete post-

http://boards.developerforce.com/t5/Apex-Code-Development/How-to-work-with-Batch-Apex/td-p/365173

 

Let me know if this information is good enough for you to go ahead for batch job creatiion and execution.