I'm having some difficulty in setting the value for a custom object from my controller extension. Here's the relevant controller code:
public with sharing class MyController {
public ApexPages.StandardController stdController { get; set; }
public AxonifyRedirectController(ApexPages.StandardController controller) {
stdController = controller;
}
public PageReference save() {
Custom__c customObject = (Custom__c) stdController.getRecord();
update customObject;
return null;
}
}
The custom object is a hierarchy type set to protected visibility.
The VisualForce page looks this:
<apex:page sidebar="false" standardController="Custom__c" extensions="MyController">
<apex:outputPanel id="myPanel"">
<apex:form>
<apex:pageBlock title="Custom Object Setup">
Please enter your custom value.<p/>
<apex:inputField value="{!Custom__c.Code__c}" /><p/>
<apex:commandButton action="{!save}" value="Save" />
</apex:pageBlock>
</apex:form>
</apex:outputPanel>
</apex:page>
I'm sure it's something ridiculously simple, but I just can't find the right documentation.
upsert customObject;
instead ofupdate customObject;
will ensure that your code will work for the creation of a new object (where there is no ID) as well as the editing of an existing object (where there is an ID).REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name]
. Any ideas?Name
field instantiated. This is either (Name field is of type String) by explicitly by assigning a value to the name field (either in your controller or indirectly through user input) - or, if the object has the name field as type autonumber, SFDC will create it for you