0

Is there a way to call future method from lightning controller? @auraEnabled and @future can co-exist together?

example:

Class ABC{ 
 @auraEnabled 
     public static void callfromFuture()
     { //some logic } 
     // if record is more than 1000 do it from future method same logic          
     @auraEnabled @future(){ 
          callfromFuture(); 
     } 
}

Will it work in this way?

  • 2
    What's the purpose behind this? You generally wouldn't want to call @AuraEnabled as a @future method, although you might call a future method from a controller method. – sfdcfox Apr 11 at 6:03
  • User selects checkbox based on which I am doing an upsert. Currently it works for 500 records but if the count goes beyond 1000 i want user to continue with UI and perform upsert operation at backend without disruption to client. – Ekta Arya Apr 12 at 9:45
  • Server actions are already asynchronous from the client's perspective. There's no reason to make your code asynchronous on the server as well. – sfdcfox Apr 12 at 10:43
  • This question looks like having the XY problem, which is asking about your attempted solution rather than your actual problem.The limit for DML Rows is 10000. You should be able to save or update up from 10000 records from your action. Why do you say you have problem when count goes beyond 1000? What is that problem? – Patlatus Apr 18 at 8:41
0

Consider using Queueable Apex, which essentially accomplishes everything that a future method does and has more flexibility when it comes to parameter types and job chaining.

  • i already have an exisitng logic for 500 records which performs upsert but if the count goes beyond 1000. i just want to recall that method without affecting the UI – Ekta Arya Apr 12 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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