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
Edwards71Edwards71 

Visualforce custom extension controller problem

Hi,

 

I'm getting an "Incompatible types since an instance of SObject is never an instance of Contract" when trying to create a very simple visualforce page.

 

Page uses standard contract conroller plus extension which will be used to populate some of the contract fields 'behind the scenes' which the user wont see on the visual force page. The visualforce page will be dealing with new records only.

 

Any ideas what's going on here? I'm stumped and it must be something simple!

 

Thanks in advance

Extension controller:

public class myContract {

    public myContract(ApexPages.StandardController controller) {

    Contract con = (Contract) controller.getRecord();
       
    }


Visualforce page:

<apex:page standardController="Contract" extensions="myContract">
<apex:form >

    <apex:pageBlock title="Historic Contract" mode="edit">
Use this form to input details of an Historic contract that does not need implementation.<p/>
Historic Contracts are needed to support active Virtual contract terms <p/>
 <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save" rerender="all"/>
                <apex:commandButton action="{!Cancel}" value="Cancel"/>

            </apex:pageBlockButtons>

  <apex:pageBlockSection title="Contract Details" columns="2">
<apex:inputfield value="{!contract.ContractNumber}" /> <p/>
<apex:inputfield value="{!contract.accountid}" /><p/>
<apex:inputfield value="{!contract.name}" required="true" style="width:350px"/>
<apex:inputfield value="{!contract.StartDate}" required="true"/>
<apex:inputfield value="{!contract.ContractTerm}" required="true"/>
<apex:inputfield value="{!contract.EndDate}" required="true"/>



</apex:pageblocksection>

</apex:pageBlock>
</apex:form>
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
Edwards71Edwards71

Thanks for this. I'll use this code for something else as its a bit neater than what I had.

 

It turns out that I had a rogue Apex class which I thought had been deleted which duplicate methods hence my problem. All works fine now that I have deleted it.

 

It's always the simple things!

All Answers

PremanathPremanath

Hi Edwards,

 

You can try this way , simply you can achive

 

<apex:page standardController="Account" extensions="MyOwnLogic">
    <apex:form >
        <apex:pageBlock title="My Content" mode="edit">
            <apex:pageBlockButtons >
                 <apex:commandButton action="{!Logic}" value="MyLogic"/>
                <apex:commandButton action="{!Cancel}" value="Cancel">
                </apex:commandButton>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="My Content Section" columns="2">
                <apex:inputField value="{!account.name}"/>
                <apex:inputField value="{!account.site}"/>
                <apex:inputField value="{!account.type}"/>
                <apex:inputField value="{!account.accountNumber}"/>
                 <apex:inputField value="{!account.ParentID}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>


public class MyOwnLogic {

    Account AccRec;
    public MyOwnLogic(ApexPages.StandardController abc) 
    {
        AccRec=(Account)abc.getRecord();
    }
    public void Logic()
    {
	System.debug('Account Values---------->'+AccRec);
        System.debug('Account Values---------->'+AccRec.name);
	System.debug('Account Values---------->'+AccRec.site);

	update AccRec;
	
    }

}



Edwards71Edwards71

Thanks for this. I'll use this code for something else as its a bit neater than what I had.

 

It turns out that I had a rogue Apex class which I thought had been deleted which duplicate methods hence my problem. All works fine now that I have deleted it.

 

It's always the simple things!

This was selected as the best answer