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

Last Fiscal year revenue

i have created a custom field in account object called Prevoius Fiscal Year Revenue.
This field needs to be created and should allow for population via batch apex that can be run when the year ends.  Button to start batch should be available on the account Detail page.

Can some body give suggestion on how to create a button to achieve functinality.

Thanks in advance
First, my assumption is that you want the Batch job to only process that particular Account, else you would just process all the accounts at the End of Year and there wouldn't be a need for the button on the Account Detail Page.  

But, let's go with this assumption for now.

I would do a few steps...
  1. Create a VisualForce page with the Account as a Standard Controller and an extension of a Custom Apex class.  In the "happy path" scenario, this VF page won't be displaying anything.  In the event of some nasty error, this page should probably display any errors.  In the case of an error being displayed, don't forget to add a "Back to Account" button.  Good UX is still a must :-)  Within the Page tag of the VF Page, I'd use the "action" attribute to call a method named "executeBatchJob" on the Custom Controller.
  2. Within the Custom Controller's "executeBatchJob" method, you can kick off your batch job.  I recommend always putting the Batch Size as a Custom Setting so that you can fine tune your app later.  If the Batch Job submits properly, I'd return the user back to the Account.  You can get the Account Id from the Standard Controller that will be passed into the Controller's constructor.  
  3. I'm assuming you have the batch job written and the Account Id is passed in as a Parameter to the Constructor or from a Setter.
Hope this helps!
Hi Shankswi,

Thanks for the reply.
can u provide me the psedo code please..