I would like to add a custom detail page button to the order page which is only executing Apex. Without displaying a new window.

For the moment, my custom button is linked to a visualforce page which is calling the order standard controller and my custom extension. After getting the order record in the constructor of my custom extension, a public method is called by the visual force page via a command button. Finally, I make a redirection to the previous order page.

My goal is to be able to get the order record in the constructor of a class, make an update on it, then redirect directly to the order page without displaying any new window.

Thanks for your help.

  • do you want to update a record with detail page button ? on same record or another record?
    – Ratan Paul
    Nov 30 '15 at 14:39
  • Hi Ratan. In fact, I use the detail page buttons for multiple differents tasks. Some are just a basic update of the same record, some are for tasks more complexes than just a simple update. But I always use the same record. Nov 30 '15 at 14:41
  • Look into the Ajax toolkit. You can do all of this via a custom JS button without the need for a middle VF page
    – Eric
    Dec 1 '15 at 16:04

You can accomplish it this way:


<apex:page standardcontroller="object__c" extension="mycontroller" action="updateMe">
    Maybe show some message here if the update fails  


public with sharing mycontroller() {
   public object__c myobj {get; set;}

   public mycontroller(ApexPages.STandardController ctr){
      myobj = ctr.getRecord();

   public pageReference updateMe() {
     //Do the update/DML here

     PageReference pageRef = new PageREference(myUrlGoesHere);
     return pageRef;
  • Hi Sebastian. Thanks for your answer. How can I get the current record with this solution? Dec 1 '15 at 8:21
  • I just edited my code. I did it from my iPad so please check for typos. :) Dec 1 '15 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.