+ Start a Discussion

handling command button functionality in an apex class using SOQL/binding.update



I have created a simple command button on a VF page which goes to an apex class method.

It simply looks like this: <apex:commandButton action="{!opcancel}" value="Cancel Opp/Order" />

The !opcancel functionality is handled in an apex class as follows:

public class OppOperations {
    public OppOperations(ApexPages.StandardController controller) {


    public PageReference opcancel() {
      opportunity[] updates = new opportunity[1];
      opportunity update_opportunity = new opportunity();
      update_opportunity.Id= '006R0000004aSPW'; //PROBLEM 1: why wont this line compile ?
            update_opportunity.Opp_Order_Status__c = 'Cancelled Order';
      updates[0] = update_opportunity;
      binding.update(updates); // PROBLEM 2: why wont this line compile
      PROBLEM 3: here I want to close the VF window that called this class as the update
                 is now complete
      return null;


Basically - I have 3 problems in the above code snippet. I want to update my opportunity status to be

'Cancelled'. I would like to use SOQL to do this based on the unique record id. Question how can I do this?

Why is my syntax wrong? I can't find code examples of this type. Also - how can I close the VF window that

called this function? I want the original window to refresh showing the updated status. Basically - I need to

use SOQL to perform customised updates on individual object records. Any help would be much appreciated.



opportunity update_opportunity = new opportunity(Id= '006R0000004aSPW');


will get the id in.


 update updates; will do the updates for you.


You don't actually close a window from insie the controller.  I guess you could redirect to a page which has an onload window.close javascript on it ?!