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

Summary of Last Year's Opportunities

I have a situation where I have one opportunity per year per account.  On the current year's opportunity record is a field for Last Year's Amount.  I'd like to populate the field based on last year's opportunity record. 


Can anyone give me some direction on a simple method to do this?


It is not going to be easy to populate the amount as you are creating an opportunity when you are in the edit mode. The amount can be populated automatically after the Opportunity is inserted. You can write an after insert trigger to do the following step. 


a) Create a List of Opportunities where Account is

b) Take the Amount from the Opportunity where the Created Date is last year. 

c) Check that you only have one record in step b. If you have more than two records than select the amount from the latest record.

d) Update the newly created opportunity with the Amount.


Hope this helps!