You need to sign in to do that
Don't have an account?
Visualforce page complains that a SQL query is needed for a standard controller extension
The error I get is:
SObject row was retrieved via SOQL without querying the requested field: Opportunity.Name
Here is my VF page (quite simple I thought)
<apex:page standardController="Opportunity" extensions="PolicyHandler">
<apex:form >
<apex:pageBlock title="Close & Bind Opportunity">
<apex:messages />
<apex:outputText value="Once you close and bind an Opportunity it can no longer be edited. Are you sure you want to proceed?"/>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Close & Bind" action="{!processCloseBoundOpportunity}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Here is my Controller, the code never gets to the yeah made it part
public PolicyHandler(ApexPages.StandardController controller) {
this.myOppty = (Opportunity)controller.getRecord();
}
public PageReference processCloseBoundOpportunity() {
try {
System.debug('*************** LOOK *************');
System.debug(this.myOppty.Name);
System.debug('***********YEAH MADE IT************');
//Do stuff
PageReference p = new PageReference('/' + myOppty.Id);
p.setRedirect(true);
return p;
} catch (Exception exp) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,exp.getMessage()));
return null;
}
}
My Controller works when I do a query, but why should I have to run a query? Shouldn't the Standard Controller getRecord() give me the ENTIRE record??? The examples I've seen in the VF doco shows that there is no need to query so I'm confused.
public PolicyHandler(ApexPages.StandardController controller) {
this.myOppty = (Opportunity)controller.getRecord();
}
public PageReference processCloseBoundOpportunity() {
try {
Opportunity oppty = [SELECT
oppty.Name,
oppty.Id,
oppty.Policy_Number__c,
oppty.Policy_Type__c,
oppty.Policy_Type_Level_II__c,
oppty.Insurance_Carrier__c,
oppty.OwnerId,
oppty.AccountId,
oppty.Split_Owner__c,
oppty.CloseDate,
oppty.Effective_Date__c,
oppty.Expiration_Date__c
FROM Opportunity oppty
WHERE oppty.Id = : this.myOppty.Id];
System.debug('*************** LOOK *************');
System.debug(oppty.Name);
Thanks all for your help!
Caleb
From a good friend:
Doesn't work like that.
If you want a field, you have toadd it to the page as a hidden input field. If it's a relationship field thenyou have to query it.