+ Start a Discussion
@GM@GM 

System.AsyncException Database.executeBatch cannot be called from a batch start, batch execute, or future method

The scheduler is calling a batch apex which will do upsert on Object1.
The trigger (after insert and after update event) written on Object1 will get execute and it will call another batch apex and it will do upsert on Object2.
The trigger (after insert and after update event) written on Object2 will get execute and it will call another batch apex and it will update Object3 [No trigger on this object ].

If all these 3 batch execute in sequentially then there is no problem but it’s not guaranteed as bez resources will not be available every time from the salesforce hence often I'll get below error for some records

Error : System.AsyncException Database.executeBatch cannot be called from a batch start, batch execute, or future method

Could you please let me know how to avoid this?

Thank you.

Regards,

GM
Veena Sundara-HeraguVeena Sundara-Heragu
I think it is a bad idea to have your triggers fire batch processes. I would suggest having those 2 trigger populate a checkbox or some field that can then be used by a scheduled job to perform the batch updates.  Then when your sheduled job performs the upsert on Object 1, the triggers will fire and set the fields up.  Have this scheduled job run at an earlier time that the scheduled jobs for Object 1 and 2.