Last active
October 26, 2021 14:49
Calling future from future
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AccountTriggerHelper { | |
// function being called at before insert | |
public static void beforeInsert() { | |
for (Account a: (List < Account > ) Trigger.new) { | |
a.accountNumber = '123456678'; | |
} | |
} | |
// function being called at after insert | |
public static void afterInsert() { | |
List < Id > accountId = new List < Id > (); | |
for (Account a: (List < Account > ) Trigger.new) { | |
accountId.add(a.Id); | |
} | |
future1(accountId); | |
} | |
// future method which takes accountid as parameters and insert a contact for those accounts | |
@future | |
public static void future1(List < Id > accountId) { | |
System.debug('In future method 1'); | |
List < Contact > con = new List < Contact > (); | |
for (Id a: accountId) { | |
con.add(new Contact(accountId = a, firstname = 'In future', lastName = 'Created')); | |
} | |
insert con; | |
// If you remove below future method call it will create new contact record | |
future2(); | |
} | |
// another future method | |
@future | |
public static void future2() { | |
System.debug('I am inside future method2'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment