0

My process I've been working on hits CPU time limit exception errors sometimes. So instead of using a batch process, I want to try to use @future methods to put some of the DML statements in the future asynchronously. I have two methods one creates a related record and one updates a record based on the related record.

Can I write something like this:

@future
 public static void futureFolk(Set<Id> filtered)
 {
  handlerclass.createRecord(filtered);
  handlerclass.updateRecord(filtered);
 }
}

Because one is based off the other I don't want to do two @future methods because one may not be finished by the time it starts. I also, want to try and seporate the concerns so I can test better so I don't think I should combine them into one giant method that inserts and updates records.

Is there a right way to do this?

If I don't use @future the records will get inserted and updated so I think that my base logic is right, just I need help with getting the order right for both to be done in the future.

  • 2
    You can use queueable classes. They are a betterment over future. The main advantage being that you can chain them so I think it will suit your case. – Sam Feb 4 '17 at 2:16
  • 2
    Whycan you not set all the data before insert? Update should not be necessary. – Adrian Larson Feb 4 '17 at 2:24
  • I'll check out the queueable class. @AdrianLarson I generate a bunch of schedule records by taking the difference between two days and dividing a currency field between them. I couldn't figure out how to mimic that logic and populate the correct field so I built the logic to create the record and then built another logic to look at that and update accordingly. – Dan Wooding Feb 4 '17 at 2:33

Your Answer

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

Browse other questions tagged or ask your own question.