You need to sign in to do that
Don't have an account?
SFDC Guest
Help me to move trigger logic into future method in helper class
I have written trigger to create a contact and assign it community user before user is created. But I am getting mixed DML issue due to the insertion setup&non setup objects in one transation.
Please show me how to move below logic in future method of helper class. We cant pass List<User> as parameter in future method. Plz let me know how to pass ids or strings in below logic.
Here is the trigger:
Please show me how to move below logic in future method of helper class. We cant pass List<User> as parameter in future method. Plz let me know how to pass ids or strings in below logic.
Here is the trigger:
trigger CreateContact on User (before insert) { List<User> listUser = new List<User>(); for (User usr : trigger.new) { if (String.isBlank(usr.contactId)) { listUser.add(usr); } } if (listUser.size() > 0) { List<Contact> newContacts = new List<Contact>(); Map<String, User> userNameMap = new Map<String, User>(); //Create Contact For Each User for (User usr : listUser) { String contactLastName = usr.lastname; userNameMap.put(contactLastName,usr); Contact con = new Contact(LastName = contactLastName); newContacts.add(con); } Insert newContacts; for (Contact con : newContacts) { //Put Contact Id's on Contacts if (userNameMap.containsKey(con.LastName)) { userNameMap.get(con.LastName).contactId = con.Id; } } } }
please dont reply if you don't know. Let someone reply.
I know how to write helper class, but unable to do future method for this scenario.
So in the future method you can do similarly as mentioned for list of contacts.