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
beachbum50beachbum50 

setting object value in code

i have created a visualforce page. when some clicks a customised button - i want to set

an object's value eg pseudo code would look like:

 

OnClick event (in visualforce page):

  my_object_record.my_field_value = "new status";

 

Can anyone point to me to a code example that shows me how to do this.

I dont want to use standard 'save' button as i don't always want to do this action on

a general save event.

tia.

bob_buzzardbob_buzzard

You can do this easily through a CommandButton.  These are linked to an action method in your controller.  E.g.

<apex:commandButton value="Search" action="{!doSearch}" status="searchStatus"/>

In this case, I have a button labelled search that invokes the doSearch method in my controller.

beachbum50beachbum50

thanks bob - understand that bit and can call an action method inmy controller extension class.

(my extension class - OppOperations -  extends a standard opportunity controller).

In the 'opcancel' method - I want to set my opportunity.status=cancelled and then save the

opportunity record - any pointers? I have read the manuals (honest) but cant find any code examples.

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

    }

    public PageReference opcancel() {
      <here is where i think i need to set status to cancelled and do the save>
      return null;
    }
    
}