You need to sign in to do that
Don't have an account?
cmarzilli
Account History Tracking with Apex
Salesforce has history tracking for many objects but nothing for accounts that I can tell.
It sounds like Apex will be able to help us here but is it the best solution? Are their other ways to do this?
Our current business problem is history tracking on the account level, there are several extremely important fields and we need to know:
-When they changed
-Who changed them
-What value was before change
-What value is after change
We could create a custom object called "Account History" that could store all the relevant info. Using APEX can we create one of these "Account History" objects each time an account is Created\Updated\Saved?
We are going through an audit and our auditors want a see a way to track... well almost everything!
Can I do it using Apex? Or should I do it some other way?
With Apex code you can create a trigger on the account object. That trigger can be configured to fire on update, insert or delete. In the case of tracking changes, the trigger gives you access to the object in two states, current (unchanged) and new (the changes). This gives you the ability to record the "from" and "to" values for any fields on the Account. You would, of course, want to implement some rules as to what kind of change warrants a history record.
In addition to insert, update and delete events, you qualify those events with regard to order, before insert or after insert for instance. In the case of audit you would create trigger for after insert, after update and after delete.
Code:
So I am testing this out and I am going along but I am having a problem with the lookup field. I created a Custom object called "Account History" and added a lookup to the account. Then added this trigger to the account object:
trigger accountAudit on Account (after insert, after update) {
}
Works great but the lookup field in the resulting account history object is blank and I am not sure how to set this. I have tried:
acctHistory.AccountID = Trigger.new.AccountID;
acctHistory.Account__C = Trigger.new.Account__C;
acctHistory.Account__C = Trigger.new.Name;
acctHistory.Account = Trigger.new.Account;
Nothing seems to work, how do I fill in the lookup field on the Account History object with the right account?
acctHistory.Account__C = Trigger.new.ID;
:smileyvery-happy:
any different using the new.ID or old.ID? In theory they should be the same...
Is this ready for production or just in the as yet unreleased APEX environment?
I need to track Account owner history and trigger work flow alerts to the pervious owner when account is taken away.
Are there any other alternative solutions out there, either within the Native app that I may be missing or custom solutions floating around?
Any assistance would be greatly appreciated.