1

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.

3
  • 1
    Using upsert customObject; instead of update 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).
    – Keith C
    Commented Oct 1, 2014 at 20:35
  • Thanks Keith. That got me past that error but now I'm getting REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name]. Any ideas?
    – John S
    Commented Oct 1, 2014 at 21:32
  • 1
    All custom objects must have the 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
    – cropredy
    Commented Oct 2, 2014 at 1:14

0

You must log in to answer this question.

Browse other questions tagged .