Apex Page :

 <apex:page standardController="account" extensions="RandomWorkSpace_Ext_Cntrl" >
    <!—note the extensions attribute above -->
      <apex:sectionHeader title="Account Edit" subtitle="{!account.name}" />
      <apex:pageMessages />  
        <apex:pageBlock title="Account Edit" mode="edit" >
            <apex:commandButton value="Save" action="{!save}" />
            <!-- add a new button to call our genericPhone() method -->
            <apex:commandButton value="Generic Phone" action="{!genericPhone}" />
            <apex:commandButton value="Cancel" action="{!cancel}" />
          <apex:pageBlockSection title="Account Info" columns="3" >
            <apex:inputField value="{!account.name}" />
            <apex:inputField value="{!account.phone}" />

Extension :

public class RandomWorkSpace_Ext_Cntrl {

    public sObject myRecord;
    public ApexPages.StandardController std;
    public RandomWorkSpace_Ext_Cntrl(ApexPages.StandardController std){
        this.std = std;
        myRecord = std.getRecord();


      public void genericPhone(){
        //These 3 sObjects have a field named 'phone'
        if ( myRecord instanceof Account ||
        myRecord instanceof Contact || 
        myRecord instanceof Lead 
          myRecord.put('phone','(818) 555-1212');

In the extension method genericPhone(), there was no update statement called upon sObject. So how the extension is able to update the record. What is the underlying concept for this ?

  • 1
    This method cannot perform any updates, as you have noted. Are you sure it's not just updated once you click the save button?
    – Adrian Larson
    Jul 20, 2016 at 11:52
  • @AdrianLarson It's almost as though his method extends phone for any of the 3 objects it's written for since it's an instance method. It isn't written to extend Account per se even though he declares it that way on his page "generically" (wrong extension class name).
    – crmprogdev
    Jul 20, 2016 at 12:08
  • you are using standardcontroller save method Jul 20, 2016 at 12:30
  • the page refers to an extension class that is different than your posted class. As an aside, action methods should generally be named verb-like
    – cropredy
    Jul 20, 2016 at 14:50

1 Answer 1


genericPhone doesn't save the change to the database. After calling, but before you click save, the in-memory representation is updated, but the change isn't persisted until save is called.

  • Yes @Sfdcfox, unless not clicked on save the changes are not saved. Only the phone value changes to the given value after clicking on genricPhone button but its not committed to the database unless save is clicked.
    – s_saiyan
    Jul 21, 2016 at 14:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .