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
EdCodeEdCode 

Queueable vs future (Trailhead)

Hi,
I am trying, without success, to understand the second paragraph below (written in Trailhead):

User-added image
My interpretation of this second paragraph is that, if you have class where one of its methods contains a if-condition statement where, under certain condition the code is executed synchonously and under other condition a code is executed asynchronously, then (according to this 2ond paragraph) you would be better off leveraging a future method? (instead of a Queueable apex?)

The question is WHY?
Could you possibly clarify/elaborate so as to fully understand the above paragraph #2?

Thank you.
Best Answer chosen by EdCode
Pablo Gonzalez Alvarez 3Pablo Gonzalez Alvarez 3
Because  say you have this method
 
public static void createAccount(){
 //some code here
}

If you want to make this async, it's as simple as wrapping it in a future method
 
@future
public static void createAccountAsync(){
    createAccount()
}

but try to convert the createAccount method to queueable...you need to create a whole new class for that
 
public class CreateAccountAsyncRequest implements Queueuable{

	public void execute(EnqueuebleContext context){
		createAccount();
	}


	void createAccount(){
		//create account here
	}

}

What's easier: Creating a whole new class (and the required code coverage) or simply creating a method to wrap another method?

The functionality is the same, they both run async, but a future method is simpler in this particular scenario.