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
carramrod81carramrod81 

Trigger to insert custom object on Account update/insert

Hello,
I have a a very very simple custom object that i'd like to use to track previous customer numbers. The customer object is Previous_User_Code and it's fields are as follows
Account Master-Detail(Account)
Previous User CodeText(20) (External ID) (Unique Case Insensitive)

There is a field on the account named User_code__c.
When updating/inserting an account, after the insert/update when there is a value in user_code__c, i'd like to make sure that there is a record in the custom object Previous_User_code. If there is, then do nothing, else insert into the custom object.

The whole point of this is our base data has some duplication and when we merge accounts, i'd like to be able to track what the previous user codes were. By making the field Previous User Code in the custom object to an external Id, i should be able to search for old codes.
I'm a VB programmer, but can't find a good book beginners book on apex, (the cookbook doesn't seem to help much with the basics, just chunks of code).


Message Edited by carramrod81 on 05-21-2008 07:08 AM
jrotensteinjrotenstein
The Cookbook should give you sufficient examples for doing this type of thing.

Have a look at the Trigger examples, especially around the Test classes since they create new objects and insert them into Salesforce.

You can also refer to the Apex Developer's Guide.