+ Start a Discussion

Can I link a button to a trigger?

I created a trigger that would not let an user create a record if a record exist for that child object.

But Can I link it to a new button. So when the user clicks new, it will fire the trigger off to check if a record is created and not let the user create another record?



Best Answer chosen by Admin (Salesforce Developers) 

If the trigger is set as 'before insert', it will always fire. You don't need to link it to a specific button. All attempts to insert a record will fire the trigger. Use the addError method to cancel the insert if a duplicate row is found: