You need to sign in to do that
Don't have an account?

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
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
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
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.
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"