Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this error that says "System.AsyncException: No enclosing class for method: methodName".

The code structure :

trigger trgSendRecords on DataSetup__c (after insert) {

    sendRequest('hello' , 'world');

    public static void sendRequest(string A , string B){




When the record is inserted on the custom object I always get an error :

System.AsyncException: No enclosing class for method: sendRequest

I have tried to put this method in a GlobalClass and then call it in the trigger but the error still remains the same.

Request you guys to shed some light on the cause and remedy for this.


share|improve this question
up vote 4 down vote accepted

It is unfortunate that the trigger compiler allows methods to be declared in triggers. We asked in a case about this some time ago and were told that this is undocumented and unsupported.

The normal pattern for what you are doing is this trigger:

trigger trgSendRecords on DataSetup__c (after insert) {
    Sender.sendRequest('hello' , 'world');

and this class:

public class Sender {
    public static void sendRequest(string A , string B) {
        // ...

where the static method invoked is qualified by its class name in the trigger. Did you try exactly this pattern?

share|improve this answer
Yes I did try this which seems to work just fine. What is strange is that it seemed to work for the first execution without any errors and then subsequently started throwing errors (or may be I'm fatigued). So apparently this is not supported, am I right? – Shaikh Mohd Nadeem Jun 17 '14 at 12:03
If you mean adding methods in triggers, then I can't say what will happen and making the method @future adds further uncertainly. Bottom line is to use the documented and supported approach. – Keith C Jun 17 '14 at 12:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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