How do I access the fields of a custom object with a standard controller?

I have a custom object called “Shows.” I’m writing a VisualForce page to display some custom data. My code is:

<apex:page standardController="Show__c">
    <apex:pageBlock id="thePageBlock" >
        <apex:pageBlockSection title="Private Event Detail" columns="1">
            <p>Account: {!show.PE_Account__c}</p>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

When I save this, I get the following error message:

Error: Unknown property 'Show__cStandardController.show'    

I’m not using an extension here because as I understand from the documentation, I shouldn’t need one. But perhaps I’m understanding it incorrectly. The Visualforce documentation says:

Salesforce includes standard controllers for every standard and custom
object.

and

Every standard controller includes a getter method that returns the
record specified by the id query string parameter in the page URL.
This method allows the associated page markup to reference fields on
the context record by using {!object} syntax, where object is the
lowercase name of the object associated with the controller.

I take this all to mean that I should be able to access data using the {!show} syntax. Clearly that doesn’t work.

Answer

You need to use the full Object API name, which is the same as the name of the standard controller:

<apex:page standardController="Show__c">
    <apex:pageBlock id="thePageBlock" >
        <apex:pageBlockSection title="Private Event Detail" columns="1">
            <p>Account: {!Show__c.PE_Account__c}</p>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Attribution
Source : Link , Question Author : eyedar , Answer Author : Matt Lacey

Leave a Comment