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
ivantsyivantsy 

Cannot create standard controller extension

Hello!

I just started using VF with Developer license, without any previous experience in Java and HTML and trying to create approval process with custom Objects and pages using standard (built in) approval setup.

I want to show Approval history on my VF page.

As I read on I-net, I need to extend standard controller (I think there should be some Approval controller) and now, for curiosity too, I am trying to extend any standard controller (as in example below - from the Internet), but I am always getting an error:

 

Compile Error: Method does not exist or incorrect signature: stdController.getRecord() at...

 

Is it related to my Developer license, or something wrong in this code (but from other posts, i see, that many people using same code)? 

Thank you. 

 

The following class is a simple example of a controller extension:

swfobject.registerObject("clippy.d3703e55", "9");
public class myControllerExtension {    private final Account acct;        // The extension constructor initializes the private member         // variable acct by using the getRecord method from the standard         // controller.         public myControllerExtension(ApexPages.StandardController stdController) {        this.acct = (Account)stdController.getRecord();    }    public String getGreeting() {        return 'Hello ' + acct.name + ' (' + acct.id + ')';    }}

The following Visualforce markup shows how the controller extension from above can be usedin a page:

swfobject.registerObject("clippy.d3703e64", "9");
<apex:page standardController="Account" extensions="myControllerExtension">    {!greeting} <p/>    <apex:form>        <apex:inputField value="{!account.name}"/> <p/>        <apex:commandButton value="Save" action="{!save}"/>    </apex:form></apex:page>
Best Answer chosen by Admin (Salesforce Developers) 
ivantsyivantsy

 

Sorry. I found a problem. 

 

Thank you! 

All Answers

ivantsyivantsy

 

Sorry. I found a problem. 

 

Thank you! 

This was selected as the best answer
icemft1976icemft1976

Hi, did you ever get the basic example to work?

 

For some reason I get an error saying the method signature isn't recognized. People suggested making the method a property but that doesn't seem to make sense...

 

thanks!

ivantsyivantsy

Hello!

 

I am replying little late, because I was trying to recall if I had same message as you have, but cannot remember.

I am new to VisualForce and I am trying/testing different ideas for future use.

Code below is working page and controller - it extends standard controller "Contact", page has one inputField.

When you type something in the box and click button - "Hello <typed text>" appears on the top.

If you will create page with code below, it should work.

 

PS. "method signature" - should be number and type of parameters, which you are passing to method. Looks like your method expects different parameters.

 

Controller code:

 

public with sharing class myControllerExtension {
private final Contact cont;

    public myControllerExtension(ApexPages.StandardController stdController) {
            this.cont = (Contact)stdController.getRecord();

    }
    public String getGreeting() {
        return 'Hello ' + cont.Title + ' (' + cont.SystemModStamp + ')';
    }


}

 

VF Page:

 

<apex:page standardController="Contact" extensions="myControllerExtension">
    {!greeting} <p/>
    <apex:form >
        <apex:inputField value="{!contact.Title}"/> <p/>
        <apex:commandButton value="Save" action="{!save}"/>
    </apex:form>
</apex:page>