function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Keith987Keith987 

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?

 

Thanks,

Keith

Starz26Starz26

Wow, it does work.....

 

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

gaisergaiser

It is documented implicitly in Defining Class Methods

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