+ Start a Discussion
Waqas AliWaqas Ali 

Invalid field ContractNumber for SObject Opportunity


 

I have a button in Opportuinty page which calls myclass, i am trying to show the contracts in visual force page, my controler is Opportunity type so now i am getting error when i try to access the "ContractNumber" in SObject Opportunity, But i need to use Opportunity controler.  NOw how should i access ContractNumber and Status in Visual force page. 
Here is my Visual force page. 

<apex:page standardController="Opportunity"
 extensions="myclass"
 action="{!autoRun}">
  
<apex:pageBlock title="My  Contracts"> 
        <apex:pageBlockTable value="{!Records}"  var="Record"> 
            <apex:column > 
                <apex:facet name="header">Contract Name</apex:facet> 
                <apex:outputText value="{!Record.Name}"/> 
            </apex:column> 
             <apex:column > 
                <apex:facet name="header">Contract Number</apex:facet> 
                <apex:outputText value="{!Record.ContractNumber}"/> 
            </apex:column> 
           <apex:column > 
                <apex:facet name="header">Contract Status</apex:facet> 
                <apex:outputText value="{!Record.Status"/> 
            </apex:column> 
          </apex:pageBlockTable> 
    </apex:pageBlock> 
</apex:page>
Here is my class.
public class  myclass {
 
    
    String theId = ApexPages.currentPage().getParameters().get('id');
    public List<Contract> Records {get; set;}

   public myclass(ApexPages.StandardController stdController) {
        this.o = (Opportunity)stdController.getRecord();
    }
     
    public PageReference autoRun() {
 Records = [select Name, AccountId, StartDate, Status, ContractNumber from Contract where Status='Pending']; 
 return null;
 }
I am new to salesforce , may be its too easy but for me its difficult. Guys any Help ! 
JD68JD68
Hi Waqas, can you post the error you are getting please (exact wording)
Thanks
JD
Waqas AliWaqas Ali

Exact wording

error:Invalid field ContractNumber for SObject Opportunity

Himanshu ParasharHimanshu Parashar
Can you please replece your class with following code
 
public class  myclass {
 
    
    String theId = ApexPages.currentPage().getParameters().get('id');
    public List<Contract> ConRecords {get; set;}

   public myclass(ApexPages.StandardController stdController) {
        this.o = (Opportunity)stdController.getRecord();

       
ConRecords = [select Name, AccountId, StartDate, Status, ContractNumber from Contract where             Status='Pending'];

    }
     
 } 

and VF Page
 
<apex:page standardController="Opportunity"
 extensions="myclass"
 action="{!autoRun}">
  
<apex:pageBlock title="My  Contracts"> 
        <apex:pageBlockTable value="{!ConRecords}"  var="Rec"> 
            <apex:column > 
                <apex:facet name="header">Contract Name</apex:facet> 
                <apex:outputText value="{!Rec.Name}"/> 
            </apex:column> 
             <apex:column > 
                <apex:facet name="header">Contract Number</apex:facet> 
                <apex:outputText value="{!Rec.ContractNumber}"/> 
            </apex:column> 
           <apex:column > 
                <apex:facet name="header">Contract Status</apex:facet> 
                <apex:outputText value="{!Rec.Status"/> 
            </apex:column> 
          </apex:pageBlockTable> 
    </apex:pageBlock> 
</apex:page>

Thanks,
Himanshu
 
VahidVahid
It does not seems to be your completed code, please put your complete code, because i can see compile error at line #17 value="{!Record.Status", Here missed "}". and as well as according to error it seems that you fetching ContractNumber field on Opp but you are supposed to access it on Contract object.