+ Start a Discussion

Brand New to Triggers

I'm trying to create a trigger that will allow me to auto-populate one field with the contents of another.  So, we want to create another account field for Account Owner, but we want it to have the current account owner to appear in the new field.  Unfortunately, it can't be done using a formula field. 


Please help!  I've never created a trigger before, so I have no clue where to start!


Check out the documentation on triggers to find out more in-depth information:

Apex Trigger Reference



Assuming you want this trigger to execute before any database commits are made, it would look something like this:



trigger DuplicateAccountOwner on Account(before insert, before update)
	for(Account a : Trigger.new)
		MyCustomOwnerField__c = OwnerId;



Hey, you should defintly check out https://sfdcwisdom.com/triggers-in-salesforce/ for complete detail on Triggers.