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
d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in 

I want to combine two button as one button

Visualforcepage:
 
<apex:commandButton value="CLICK TO CREATE ORDER" action="{!post}" disabled="{!hide}" >

<apex:commandButton onclick="insert_numbers()" action="{!save}" 
                value="Insert Numbers and Save" rerender="mytable" />

Apex Coding:
 
public PageReference save() {  
     update ob; 
     refreshPage=true;             
     return null;    
    }

  public void post(){        
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http(); 
        req.setMethod('POST' ); // Method Type

What i am doing .I am updating in the save button and http post is done in the second button.

I have tried to update it on post method but it is not taking .

I want to use only one button for these two actions .How can i do it
Best Answer chosen by d.tejdeep@nicomatic.in
EnreecoEnreeco
Hi,
you cannot do a callout after doing a DML (your update).
You can do something like this:
public PageReference save() {  
     update ob; 
     refreshPage=true;       
     post(ob.Id);      
     return null;    
    }
 @future(callout=true)
  public static void post(ID objectId){        
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http(); 
        req.setMethod('POST' ); // Method Type

Basically you are doing the update in the save method (the only action of your single button in the page), and then executin a future method (that can do a callout) passing in your object id (if it is not needed the method can have no parameters on it: future calls must be static and can only have simple types on its signature, so no SObject can be passed).
This way you will only use 1 method to do both things.

All Answers

EnreecoEnreeco
Hi,
you cannot do a callout after doing a DML (your update).
You can do something like this:
public PageReference save() {  
     update ob; 
     refreshPage=true;       
     post(ob.Id);      
     return null;    
    }
 @future(callout=true)
  public static void post(ID objectId){        
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http(); 
        req.setMethod('POST' ); // Method Type

Basically you are doing the update in the save method (the only action of your single button in the page), and then executin a future method (that can do a callout) passing in your object id (if it is not needed the method can have no parameters on it: future calls must be static and can only have simple types on its signature, so no SObject can be passed).
This way you will only use 1 method to do both things.
This was selected as the best answer
d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in
Thanks very much for your reply