+ Start a Discussion

Methods can be defined in triggers?

A colleague wrote a working trigger today in which he included a method definition. Here is a contrived example that is similar to what he wrote:

trigger XXXX on Contact (after update) {

    String s = getString();
    System.debug('>>> string is ' + s);
    String getString() {
        System.debug('>>> getString called');
        return 'abcdef';

 Does anyone have any insight into this capability? Is it accidental or by design? Is it documented anywhere?





Wow, it does work.....


I do not recall documentation on this but I guess it works just like any other class.....


It is documented implicitly in Defining Class Methods

>>Cannot be declared as static when used in a trigger.