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
Kannan RamasamyKannan Ramasamy 

HttpCallouts in Batch Apex

Hi ,

I am looking for an advice on how to approach for this case.

 

I have to synchronize the salesforce Account object into My application. While synchronize, I am generating unique value in my application for newly created account. That unique value needs to update in salesforce.

 

I am using HttpCallout to make request and get response. I am raising request from Apex trigger. This implementation works fine when we are creating or updating single object.

 

Sometimes we are creating bulk account object in saleforce using third party tool.  That time I am getting “Too many future callout expection”, because it exceeds callout limitation.

 

Now I am planning to implement using Batch Apex.

 

 Is it good approach start the batch apex inside the trigger?  Because I don’t like having button in vf page and start batch apex by clicking that button. I want that synch process should be automatic not manual.

 

Is it good using batch apex for updating single entity?

 

Is active batch apex limitation for User specific or salesforce instance?



Best Answer chosen by Admin (Salesforce Developers) 
spraetzspraetz

it's okay to start a batch process inside a trigger if you know for certain that the object is not goign to be updated very often . It sounds like Accounts will be updated with some frequency so this is not something I would do.

 

Instead, I would create a scheduled batch job that runs every hour that looks for accounts that have been created/updated in the last hour or have been flagged in your trigger to be updated.  It will then iterate through those and process them and reset the flag.

 

It is not good to use batch apex to update a single entity, what you could do is check how many entities you need to update and if it is from 1 to 10, use your current approach.  However it is is greater than 10, you could flag them to be updated by your scheduled process.

 

Active batch limitation is for your organization.  You can't have more than 5 jobs running at a time.  If you do, the 6th one will fail to enqueue.

 

Hope this helps.  Let me know if you have any other questions. 

All Answers

spraetzspraetz

it's okay to start a batch process inside a trigger if you know for certain that the object is not goign to be updated very often . It sounds like Accounts will be updated with some frequency so this is not something I would do.

 

Instead, I would create a scheduled batch job that runs every hour that looks for accounts that have been created/updated in the last hour or have been flagged in your trigger to be updated.  It will then iterate through those and process them and reset the flag.

 

It is not good to use batch apex to update a single entity, what you could do is check how many entities you need to update and if it is from 1 to 10, use your current approach.  However it is is greater than 10, you could flag them to be updated by your scheduled process.

 

Active batch limitation is for your organization.  You can't have more than 5 jobs running at a time.  If you do, the 6th one will fail to enqueue.

 

Hope this helps.  Let me know if you have any other questions. 

This was selected as the best answer
Kannan RamasamyKannan Ramasamy

Thanks Spraetz, They were useful for me to take a decision.

 

 i want that  synch process needs  to run within 30 minutes. But Apex scheduler should run minimum one hour interval. Is it possible to run a scheduler with 30 minutes interval by having multiple schedulers?

 

For example:

 

        I have two schedulers and its calling same batch job. If each scheduler starts 30 minutes interval, Will it work?

 



spraetzspraetz

Yes, that will work.