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

Execute action methods from VF page witout using a button or link

We have a situation where we need to execute multiple apex classes based on the current record id using a custom button on the detail page layout.


these actions will have DML statements with heavy calcuations and updates on multiple objects


We do not want to take any user inputs or an intermediate button clicks. We just want the user to click on the custom button, then this page should execute the apex classes and redirect back to the records detail page.


Please let me know any ideas and if possible some exeample codes.




You can do that, but do be mindful that it violates Security Review best practices (performing a DML without confirming the action). It looks like this:


<apex:page extensions="mycontroller" action="{!doaction}">

If "doaction()" returns a pagereference, it will redirect to that pagereference's url. You can use this to return to your original page.