+ Start a Discussion
Abhijit Shrikhande 10Abhijit Shrikhande 10 

Controller Extension does not bind correctly to the page.

I have two visual force pages. One for edit and another for save. From the edit page, I am calling a function in the controller extension, where I am attepmting to save the record. The name of this function is "QuoteNow
public PageReference QuoteNow()
    {
       string sfdcoperation = '';
        PageReference pageRef = ApexPages.currentPage();
        try
        {
            System.Debug('opp amount '+ opportunity.Amount);
            if (this.opportunity.id == null) 
            {
                System.Debug(this.opportunity);
                insert this.opportunity; 
            }
            else
            {
                update  this.opportunity;
            }
            System.Debug('new opp created ' + opportunity.Id);  
}

I am unable to see any values for this record. I have the following line of code in my constructor.
 
public OppExtension(ApexPages.StandardController stdController) 
    {
        System.Debug('Constructor of OppExtension');
        System.Debug('Standard controller - ' + stdController);
        try{
            
        this.opportunity= stdController.getId()!=null?
                          [SELECT  X42Id__c,
                                ConstructionPts__CP_Project__c,
                                Project_Name__c,
                                Project_Country__c,
                                Project_Zip_Postal_Code__c,
                                Project_State__c,
                                Project_City__c,
                                Project_Address__c,
                                Project__c,
                                RecordTypeId,
                                StageName,
                                AccountId,
                                Name,
                                CloseDate,
                                Id,
                                Product_Type__c,
                                Floors__c,
                                Contact__c,
                                Construction_Services_Involved__c,
                                LeadSource,
                                Delivery_Date__c,
                                Committed_Date__c,
                                Completed_Date__c,
                                OwnerId,
                                Amount
                                FROM Opportunity
                           WHERE Id = :stdController.getId()]:
                           new Opportunity();
} catch(Exception ex)
                           {
                            //Not hitting exception.
                            System.Debug('We are in exception '+ex.getMessage());
                           }


This is my visual force page.
<apex:page standardController="Opportunity" extensions="OppExtension" tabstyle="Opportunity" standardStylesheets="true">
	<apex:sectionHeader title="Opportunity Edit" subtitle="{!Opportunity.name}"/>
	<apex:form >
		<apex:pageBlock title="Opportunity Edit" mode="edit">
			<apex:pageBlockButtons location="top">
				<apex:commandButton title="Save Record." value="Quote Now" action="{!QuoteNow}" rendered="{!showQuoteNowButton}"/></apex:pageBlockButtons>
            <apex:pageBlockSection title="Naming convention: Party Name-Branch Name-Site Location-Project Description" columns="1">
                <apex:inputField value="{!Opportunity.Name}" required="true"/>
                <apex:inputField value="{!Opportunity.Floors__c}" required="true"/>
                <apex:inputField value="{!Opportunity.OwnerId}" required="false"/>
                <apex:inputField value="{!Opportunity.StageName}" required="true"/>                
                <apex:inputField value="{!Opportunity.AccountId}" required="true"/>
                <apex:inputField value="{!Opportunity.Amount}" required="true"/>
                <apex:inputField value="{!Opportunity.Product_Type__c}" required="true"/>                
                <apex:inputField label="Activation date" value="{!Opportunity.CloseDate}" required="true"/>        
</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
</apex:page>
Is there something that I am missing?
Best Answer chosen by Abhijit Shrikhande 10
Abhijit Shrikhande 10Abhijit Shrikhande 10
Yes. I was missing something. This is now resolved. I had to create a copy of the standard controller so that I get the values from the page and not from the database.