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
Siddardha Jonnalagadda 4Siddardha Jonnalagadda 4 

Hi I am trying to execute the following code but it is giving me a error please help me with this

Apex Code:
public class savecontroller {
private final Account acct;
    public savecontroller(ApexPages.StandardController controller) {
        this.acct = (Account)controller.getRecord();
    }
    public void autosave()
    {
        update acct;
    }  
}

Visual Force Page code:
<apex:page standardController="Account" extensions="savecontroller">
<apex:form >
<apex:pageblock >
<!-- The action function which calles the Apex function 'autosave' -->
<apex:actionFunction name="autosave" action="{!autosave}" rerender="out" status="savestatus"/>

<!-- A status denotion of the update -->
<apex:actionStatus id="savestatus">
          <apex:facet name="start"> Auto Saving....</apex:facet> 
</apex:actionStatus>

<apex:pageblocksection columns="2">
      <apex:inputfield value="{!Account.Name}"/>
      <apex:inputfield value="{!Account.BillingCity}"/>
      <apex:inputfield value="{!Account.BillingCountry}"/>
      <apex:inputfield value="{!Account.BillingState}"/>
</apex:pageblocksection>      
</apex:pageblock>

<!-- A javascript recursive function which calls itself every 10 seconds, the setTimeout method calls the apex function 'autosave' defined in the <apex:actionfunction> tag above -->
<script>
          window.setTimeout(recursivecall,10000);
          function recursivecall()
          {
              window.setTimeout(recursivecall,10000);
              autosave();
          }    
</script>
                
</apex:form>      
</apex:page>

Error:

Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Error is in expression '{!autosave}' in page sample: Class.savecontroller.autosave: line 8, column 1
Best Answer chosen by Siddardha Jonnalagadda 4
Charisse de BelenCharisse de Belen
Hi Siddardha,

The problem is that if the Account does not exist yet, you cannot update it. I recommend replacing "update" with "upsert" in your autosave method.

​I hope this helps.

All Answers

Charisse de BelenCharisse de Belen
Hi Siddardha,

The problem is that if the Account does not exist yet, you cannot update it. I recommend replacing "update" with "upsert" in your autosave method.

​I hope this helps.
This was selected as the best answer
Ashish Agarwal 31Ashish Agarwal 31
Hi Siddardha,

Make sure you have an Account ID as a parameter in the URL of your visualforce page.

Sample URL : https://"salesforce_instance"/apex/pageName?Id="AccountId"