+ Start a Discussion
sebipinnsebipinn 

Pass Trigger Object as Argument

Is there a way to pass the Trigger as an argument? I know I can pass a member of the Trigger object, but I want it in its entirety.
Best Answer chosen by Admin (Salesforce Developers) 
WesNolte__cWesNolte__c

Hey

 

It's not possible in any way I know of. Here you can find some pretty darn sweet suggestion on writing OOP triggers.

 

Wes

All Answers

jdl2009jdl2009

You mean the map or list of records to be processed by a trigger? 

 

new

A map of IDs to the new versions of the sObject records.

Note that this map is only available in before update, after insert, and after

update triggers.

 

newMap

Returns a list of the old versions of the sObject records.

Note that this sObject list is only available in update and delete triggers.

 

old

A map of IDs to the old versions of the sObject records.

Note that this map is only available in update and delete triggers.

 

oldMap

A map of IDs to the old versions of the sObject records.

Note that this map is only available in update and delete triggers. 

sebipinnsebipinn

No, I want to pass the entire Trigger at once. I know that I can pass Trigger.new. This is a better example of that i want.

 

 

SomeAbstractClass.doSomething(Trigger);

 

 

instead I have to do something like so...

 

SomeAbstractClass.doSomething(Trigger.new, Trigger.oldMap);

 

 

Or cannot make the class completely abstract. i would need to instantiate the class and assign members... as you can see this is more work than necessary.  Perhaps there's a System getter i'm not aware of that exposes the Trigger object inside of the abstract class? This would be the answer I'm looking for I guess. But I'd rather pass it as an argument. I'm doing this because I want to take advantage of class methods to organize my code for this complex step I am working on. Plus, i want to reuse the code.

 

Thanks

WesNolte__cWesNolte__c

Hey

 

It's not possible in any way I know of. Here you can find some pretty darn sweet suggestion on writing OOP triggers.

 

Wes

This was selected as the best answer
sebipinnsebipinn

Thanks for the reply.  I created similar approaches already but it would just be nicer to pass the trigger object, or have access to it from a global level. maybe this is suited best in the idea exchange. Thanks again.

WesNolte__cWesNolte__c

I completely agree. I even suggested in the comments on that page:)

 

Cheers.