function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jenhop4681jenhop4681 

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!

jbroquistjbroquist

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;
	}
}

 

 

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