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
mDizz_7mDizz_7 

Tracking History the hard way

Hello everyone, I'm pretty new to developing and my org has just run accross a problem. We need to track history on product changes within the Opporunitiy. I know this is not supported nativly. My thought is that we can run a trigger and populate a list of changes. However I'm not sure where to start on this. Any references or advice would be helpful. Thanks in advance!

Best Answer chosen by Admin (Salesforce Developers) 
dmchengdmcheng

You'll need a trigger on OpportunityLineItem that covers inserts, updates, and deletes.  Fairly straightforward, but if you're just getting started, it is a significant amount of work.

 

Here are resources for getting started on writing triggers:

http://wiki.developerforce.com/page/Documentation

 

And you will need to write unit tests to deploy your code to production:

http://wiki.developerforce.com/page/How_to_Write_Good_Unit_Tests

All Answers

LoserKidLoserKid

Not sure if this works here but you can track history, i think, any field in salesforce. In fact i just checked and we have Staging History on our Opporunities, which sound like what you want.

 

- OR -

 

You can use a custom object. i did some similar with time traking. for this, i would create the object with a large text box. then create a trigger on opportunity that on insert create its child custome object. then you can just write out the changes in the test field. 

dmchengdmcheng

Please clarify - are you saying that you are using Products with your Opportunities, and that if a Product is added or removed from an Opp, you want to track that change in a field in the Opp?

mDizz_7mDizz_7

Sorry to delay, I really appreciate the help. To clarify, We are using products in our opportunities and we need to track the history of the changes to the prioducts within that same opportunity.

dmchengdmcheng

You'll need a trigger on OpportunityLineItem that covers inserts, updates, and deletes.  Fairly straightforward, but if you're just getting started, it is a significant amount of work.

 

Here are resources for getting started on writing triggers:

http://wiki.developerforce.com/page/Documentation

 

And you will need to write unit tests to deploy your code to production:

http://wiki.developerforce.com/page/How_to_Write_Good_Unit_Tests

This was selected as the best answer