You need to sign in to do that
Don't have an account?
Calling synchronous method inside a future method
Hi,
I need to know what will happen when a synchronous method called inside a fututre method. Will it run synchronously or it will also start its execution in asynchronous manner. Also please tell me what will happen if the called method is having any return type?
Thanks
Example:
@future
static void myFutureMethod(List<String> params) {
// call synchronous method
mySyncMethod(params);
}
I need to know what will happen when a synchronous method called inside a fututre method. Will it run synchronously or it will also start its execution in asynchronous manner. Also please tell me what will happen if the called method is having any return type?
Thanks
Example:
@future
static void myFutureMethod(List<String> params) {
// call synchronous method
mySyncMethod(params);
}
Yes, We can call a synchronous method inside a future method.
Both will run on Asynchronous Only.
Please check sample code below :
For confirmation please check debug logs.
Hope it helps you.
Please let me know in case of any other assistance.
Thanks
Varaprasad
All Answers
Yes, We can call a synchronous method inside a future method.
Both will run on Asynchronous Only.
Please check sample code below :
For confirmation please check debug logs.
Hope it helps you.
Please let me know in case of any other assistance.
Thanks
Varaprasad
What error will occur if there is a return type in synchronus method?
Future method return type is void only.
But synchronous method will contain any return type.
It will not through any error.
Please check once below code :
Please execute code in the anonymous window and check once.
Synchronous
In simple terms you can assume Synchronous as Sequential. In Synchronous process the thread waits for the task to be completed and then moves to the next task Sequentially. All the tasks are completed in a single thread.
The common example of a Synchronous apex is Trigger.
Asynchronous
In Asynchronous apex the thread does not waits for the task to be completed to move on to the next task. The tasks are run in different threads all together. These threads run in independent silos whenever the system is free.
I hope it helps you.
Please let me know in case of any other help.
If above information helps you please mark it as the best answer.
Thanks
Varaprasad
Will both of them will be considered as separate transaction or not?