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
Matt_FMatt_F 

Receiving System.TypeException: Invalid conversion from runtime type SOBJECT

Any help that can be provided will be greatly appreciated.

 

I'm not sure what the problem is, but I am receiving the following error:

 

System.TypeException: Invalid conversion from runtime type SOBJECT:Opportunity to SOBJECT:Value_Tests__c

Class.ValueTestExtension.<init>: line 5, column 1

 

Extension

public with sharing class ValueTestExtension {
    Opportunity o;
    Value_Tests__c vt;
    public ValueTestExtension (ApexPages.StandardController controller){
        vt = (Value_Tests__c) controller.getRecord();
    }
    public List<Value_Tests__c> getValueTests(){
        return [SELECT actual_completion_date__c, approval_date__c, Outcome__C FROM value_tests__c WHERE OppID__c = :o.id];
            }
}

 VF Page:

<apex:page standardController="Opportunity" extensions="ValueTestExtension">
  <apex:pageBlock >
    <apex:pageBlockSection columns="1" title="Opportunity Detail Info">
      <apex:outputField value="{!opportunity.name}"/>
      <apex:outputField value="{!opportunity.ownerId}"/>
    </apex:pageBlockSection>
    
    <apex:pageBlockSection columns="1" title="Value Test Info">
      <apex:pageBlockTable value="{!ValueTests}" var="vt">
        <apex:column value="{!vt.Actual_Completion_Date__c}"/>
        <apex:column value="{!vt.Approval_Date__c}"/>
      </apex:pageblockTable>
    </apex:pageBlockSection>
    
   </apex:pageBlock>
</apex:page>

 Again, I appreciate any help you can give me.

 

Thanks,

 

Matt

 

SFFSFF

Your VF page uses the "Opportunity" standardController. So the type of the controller.getRecord() record is "Opportunity". So what this error is saying is that you cannot cast an Opportunity to a Value_Tests__c at line 5.

 

What you probably want to do is:

 

public with sharing class ValueTestExtension {
    Opportunity o;
    Value_Tests__c vt;
    ID oppId;
    public ValueTestExtension (ApexPages.StandardController controller){
        OppId = controller.getRecord().Id;
    }
    public List<Value_Tests__c> getValueTests(){
        return [SELECT actual_completion_date__c, approval_date__c, Outcome__C FROM value_tests__c WHERE OppID__c = :oppId];
            }
}

Good luck!

Matt_FMatt_F

Thanks a lot, John.  That worked.  But now I have a new problem.  For some reason, no data will show under the Value Test Info section.  I am trying to create a form for users to fill out to request a value test (which is the value_tests__c object).  Do you think I am going down the correct path?

 

<apex:page standardController="Opportunity" extensions="ValueTestExtension">
 <apex:form >
  <apex:pageBlock >
    <apex:pageBlockSection columns="2" title="Opportunity Detail Info">
      <apex:outputField value="{!opportunity.name}"/>
      <apex:outputField value="{!opportunity.ownerId}"/>     
    </apex:pageBlockSection>
    
    <apex:pageBlockSection columns="2" title="Value Test Info">
      <apex:pageBlockTable value="{!ValueTests}" var="vt">
        <apex:inputfield value="{!vt.Approval_Date__c}"/>
      </apex:pageblockTable>
    </apex:pageBlockSection>
    
   </apex:pageBlock>
 </apex:form>   
</apex:page>