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
RoyalRoyal 

@future method ?

what is exact scenario to demon work with @future annatation ?

Thanks
surasura
you can use future methods for asyncronous processing requirements . you can  find more details at https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm. I frequently use future methods to avoid governor limit exceptions in complex transactions
NagaNaga (Salesforce Developers) 
Hi Sfdc,

A future method runs in the background, asynchronously. You can call a future method for executing long-running operations, such as callouts to external Web services or any operation you’d like to run in its own thread, on its own time. You can also make use of future methods to isolate DML operations on different sObject types to prevent the mixed DML error. Each future method is queued and executes when system resources become available. That way, the execution of your code doesn’t have to wait for the completion of a long-running operation. A benefit of using future methods is that some governor limits are higher, such as SOQL query limits and heap size limits.

See the sample below

User-added image

Please follow the below links for more information

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_invoking_future_methods.htm

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm

Best Regards
Naga Kiran
 
ManojjenaManojjena
Hi sfdc351,

Basically future annotation is just like multithreading concept in Java .
Please follow below point with one scenario it will help .

1.Method which annoted with @Future annotation is called Future method .
2.Future method  must be static , and can only return a void type.
3.Parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types but not sobject .
4.You can not call a future method from other future method .
5.Method like getContent and getContentAsPDFPageReference  
6.Future method cannot call  methods  like getContent and getContentAsPDFPageReference .
7.Future method will not execute with the oreder you called it may very based on the availability of resource .

One use case :-
If you are doing any DML in same transaction for both setup and nonsetup object then one error will be thown by run time Named MIXED_DML_OPRERATION .

basically in community we are creating user from Conatct . So while creating user from contact we are giving related account access to the user .
So have achived this through trigger ,So we have created handelr class and use future annotation in method to avoid  this .
to avaoid that you can use future method .

Same issue in test calss ,you can check this link .

http://stackoverflow.com/questions/2387475/how-to-avoid-mixed-dml-operation-error-in-salesforce-tests-that-create-users

To get more detail about setup and nonsetup object and MIX_DML_Operation you can check below links .

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dml_non_mix_sobjects.htm





 
RoyalRoyal
Hi,
@future(callout=true) methods are allowed calls from external system  as asynchronously ?
       or
 this method can able to call external system as asynchronously ?
whitch is currect ?

thanks