Trigger to avoid recursive trigger call on contact object (create contact) - Salesforce
Handler class:
public class ContactInsertHandler { public static void createContact() { Contact cont = new Contact(); cont.LastName = 'Dharmik'; insert cont; } private static boolean run = true; public static boolean runOnce(){ if(run) { run=false; return true; } else { return run; } } } |
Trigger:
trigger InsertContact on Contact (after insert) {
if(ContactInsertHandler.runOnce())
{
ContactInsertHandler.createContact();
}
}
if(ContactInsertHandler.runOnce())
{
ContactInsertHandler.createContact();
}
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment