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
Michael RotterMichael Rotter 

how to have more than one future method in a single class

I currently have a class with two fututre classes that has no compiler errors, but when I run it through the execute anonymous window I get the error that "only the top level class can be static". How can I have two static methods in the same class without having the static error?
Glyn Anderson 3Glyn Anderson 3
In your question you seem to be confusing classes and methods.  Classes contain methods.  Classes cannot be static or @future - they can be global, public or private.  Methods can be static and @future, in addition to being global, public or private.  Only outer classes can contain static methods (or static members of any kind).  Because @future methods must be static, they can only exist in outer classes.  You can define as many @future methods as necessary in your outer class.

Try something of the form:

<pre>
public class MyClass {
    @future
    public static void myFirstFutureMethod() {
        // do something here
    }
    @future
    public static void mySecondFutureMethod() {
        // do something here
    }
}
</pre>

These will be called using the syntax:

    MyClass.myFirstFutureMethod();
 
Michael RotterMichael Rotter
Hey Glyn, I just reread my post and realized that you are correct. I meant to say I have two @future methods in one class. My class looks similar to the snippet you posted, so is what you are saying that I should simply call the methods in the execute anonymous window using the syntax you described?
Glyn Anderson 3Glyn Anderson 3
I think that will work.  Try it and let me know.  I tend not to define classes and methods in the Execute Anonymous window.  But if you deploy the class to your org, you can certainly call the methods from the anonymous window.
Michael RotterMichael Rotter
That doesn't seem to be working either. It's strange. So this class is called from a VF page when a button on the Case page is clicked and when I have the future methods in the program it doesnt seem to work. However, if I remove the @futures and make the methods not static, it seems to work. The problem is that I think I need those methods to be @futures. Any thoughts?
 
Glyn Anderson 3Glyn Anderson 3
Michael, can you post your code?  You can remove the bodies of the methods - just want to see how the class and @future methods are declared, and how they are invoked from your controller.  Thanks!
Michael RotterMichael Rotter
Hey sorry for the late reply. Here's the code:
public class JiraConnector { 

@future (callout = true)
 public static void SyncWithJira(List<id> caseIds) {
      // 
    }
    
  
     @future (callout = true)
//Syncing SFDC and Jira when updates are made to SFDC case
       public static void updatejira(string Description,string Subject,string Bug_Number_c,string CaseNumber) {        
     //
}

}

 
Michael RotterMichael Rotter
There is some other code outside of the two @future methods but I just wanted to show you how they are set up