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
HelmetHelmet 

Increment a field and compare its values

Hi everyone, I am new here and I hope that you could help me !

I want to create a field of a revenue for example, and I want it to increment each year: the revenue of this year is the of this year +( n-1) years. And also have the capability to compare the different values of the same field in different years, to know how it increases...

Thanks a lot.

Richard Jimenez 9Richard Jimenez 9
Hi Mohamet,

Check out using reporting snapshots that can run & store a copy of report data at a point in time in a custom object which you can use in a report to compare with. Check out the details here: https://help.salesforce.com/HTViewHelpDoc?id=data_about_analytic_snap.htm&language=en_US

How many years do you want to retain? If you only want to keep the last 3-4 years, you can create 3-4 revenue year fields on your object, and use a time-based workflow rule to fire are the end of your financial year that copies the last but one year down, then have a workflow rules to fire on the change of that that year revenue to update the next one up (so you'll need a workflow for each revenue year field) - not ideal.

Hope that helps,
Richard.
Mahesh DMahesh D
Hi Mohamet,

If you can provide the Data Model along with some sample data, it will be easy to help you on this issue.

Regards,
Mahesh
HelmetHelmet

Thanks Richard and Mahesh for your answers.

What I want to do is to have a field, which its first value is the one that the client insert, then it will increment by years. How can I calculate the growth rate from one year to another. 

For example: in the beginning it was 100 then 125, so it increases by 25%....

I really hope that you could help me, thanks again.

Mahesh DMahesh D
Hi Mohamet,

One solution is, you can implement it using the Batch Apex which will run yearly once.

Here is the information about the Batch Apex:

A Batch class allows you to define a single job that can be broken up into manageable chunks that will be processed separately.

When to use Batch Apex
One example is if you need to make a field update to every Account in your organization. If you have 10,001 Account records in your org, this is impossible without some way of breaking it up. So in the start() method, you define the query you're going to use in this batch context: 'select Id from Account'. Then the execute() method runs, but only receives a relatively short list of records (default 200). Within the execute(), everything runs in its own transactional context, which means almost all of the governor limits only apply to that block. Thus each time execute() is run, you are allowed 150 queries and 50,000 DML rows and so on. When that execute() is complete, a new one is instantiated with the next group of 200 Accounts, with a brand new set of governor limits. Finally the finish() method wraps up any loose ends as necessary, like sending a status email.

Sample Batch Apex
1) Start method is automatically called at the beginning of the apex job. This method will collect record or objects on which the operation should be performed. These record are divided into subtasks & passes those to execute method.

2) Execute Method performs operation which we want to perform on the records fetched from start method.

3) Finish method executes after all batches are processed. Use this method to send confirmation email notifications.

Please go through the below links for more information:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm

https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_batch_intro.htm

http://www.infallibletechie.com/2013/01/simple-batch-apex-example-in-salesforce.html

http://www.salesforcetutorial.com/what-is-batch-apex/

http://www.salesforcetutorial.com/running-batch-apex-example/

https://www.youtube.com/watch?v=PmvpMakxpm8

http://blog.shivanathd.com/2013/01/how-to-write-batch-class-in.html

https://www.minddigital.com/how-to-call-batch-apex-by-scheduler-class-within-salesforce/

Please do let me know if it helps you.

Regards,
Mahesh