Can we call trigger from batch apex? If yes where should we call and if not then why?

  • 1
    You don't call triggers directly anywhere. You perform a DML operation on sObjects, and the trigger will automatically fire. If your batch apex is performing DML (insert, update, delete, undelete) and you have an active trigger in the system for one of those events, the trigger will fire.
    – martin
    Feb 22 '16 at 9:46
  • do a dummy update on the object. update myObject; Feb 22 '16 at 10:19

There is no specific place from where you call a trigger. Trigger code automatically executes when certain events such as insert, update, delete etc occur. The source for such events could be anything. For eg -

  • Button click on visualforce page or on detail page of a record causing an insert/update/delete
  • An apex code with DML statements(this could be a regular Apex class, batch class, or even some other trigger)
  • Workflow field updates...

From the Trigger Docs:

A trigger is Apex code that executes before or after the following types of operations:

Not the answer you're looking for? Browse other questions tagged or ask your own question.