I wants to create trigger which will run on all sobjects. Something like

Trigger myTrigger on Sobject(after insert){}

That is not possible both in terms of the syntax and the functionality you are trying to achieve. There are a lot of sObjects out there that don't support triggers.

What you could do is create a class that operates on the generic sObject, and have a bunch of individual triggers call that class.


public class Trigger_SObject {
    public static void doSomething(list<SObject> TriggerNew){
        for (SObject so : TriggerNew) system.debug(so.get('Name'));

Trigger (make one for each object you want the code to act on)

trigger Account on Account(after update) {
    Trigger_SObject.doSomething( (list<SObject>) Trigger.new );
| improve this answer | |
  • For sure i already planned to do what you suggest.. Just wonder exist such a way.. thanks – hcohen Aug 31 '16 at 7:48
  • Probably would be good to implement some sort of handler cache, e.g. Map<SObjectType, TriggerHandler>. – Adrian Larson Aug 31 '16 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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