0

I want to understand this error as I have never seen this before.

Content cannot be displayed: Invalid conversion from runtime type L1dlF0rm0rg__Case__c to ICIX_V1__ICIX_Product__c

Background: I am trying to use a visualforce page & extension to view records associated through a lookup (not the related list records, the "parent") I am trying to invoke the standard controller for my case__c object in my extension. So, I can put this visual force page in the detail of the case__c object. (record details) currently just bringing the name is so I can see if it works. I will bring in other specific fields later on.

But, I wanted to understand the error that I am getting so I can better troubleshoot this. I have researched this, but I do not see much information that describes the error to be.

code:

Extension:

    public with sharing class CaseParentExt {

    public ICIX_V1__ICIX_Product__c prods{ get; set; }
    public ApexPages.StandardController stdController;

    public CaseParentExt(ApexPages.StandardController stdController) {
        this.prods = (ICIX_V1__ICIX_Product__c)stdController.getRecord();
        this.stdController = stdController;
    }  
    public void CaseParentExt() {

        String prodsId = ApexPages.currentPage().getParameters().get('id');
        prods = [SELECT Id, Name FROM ICIX_V1__ICIX_Product__c WHERE Id =: prodsId];
    }

}

VFP:

<apex:page standardController="L1dlF0rm0rg__Case__c" extensions="CaseParentExt">
   <apex:form >
        <apex:pageblock title="Related Products">
            <apex:pageMessages />
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Product Name</apex:outputLabel>
                    <apex:outputText >{!prods.Name}</apex:outputText>   
                </apex:pageBlockSectionItem>              
            </apex:pageBlockSection>
        </apex:pageblock>
    </apex:form>
</apex:page>
  • 2
    Your standard controller in your visualforce page is not the same type as the record returned by the standard controller in your extension class. – Martin Lezer Jan 5 '17 at 8:20
  • @MartinLezer ahh, I see your logic in this. So to correctly fix this, can I change the standard controller to ICIX_V1__ICIX_Product__c on the visualforce page, and then re-align my prods SELECT statement, because I am grabbing the Id from the ApexPages.currentPage which is a record from the L1dlF0rm0rg__Case__c sObject. – Jason Jan 5 '17 at 8:28
0

I'm trying to answer your comment @Jason. Your CaseParentExt method is useless. Here's the right code for your extension class:

public with sharing class CaseParentExt {

    public L1dlF0rm0rg__Case__c Case{ get; set; }

    public CaseParentExt(ApexPages.StandardController stdController) {
        Id caseId = stdController.getId();
        this.Case = [SELECT ICIX_Product__r.Name FROM L1dlF0rm0rg__Case__c WHERE Id = :caseId];
    }  

}

And the VF page with the right standard controller:

<apex:page standardController="L1dlF0rm0rg__Case__c" extensions="CaseParentExt">
   <apex:form >
        <apex:pageblock title="Related Products">
            <apex:pageMessages />
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Product Name</apex:outputLabel>
                    <apex:outputText >{!Case.ICIX_Product__r.Name}</apex:outputText>   
                </apex:pageBlockSectionItem>              
            </apex:pageBlockSection>
        </apex:pageblock>
    </apex:form>
</apex:page>
  • your code gives me a different error. "Content cannot be displayed: List has no rows for assignment to SObject" . So that tells me that there are no ICIX_Product__c records with the same Id as the record I am viewing. And that is correct, there should not be any ICIX_Product__c records with the same Id as my L1dlF0rm0rg__Case__c record. So, I am trying to return the ICIX_Product__c record that is related to the L1dlF0rm0rg__Case__c. The ICIX_Product__c is the "parent" of the L1dlF0rm0rg__Case__c record. (it's only a lookup, not MD) – Jason Jan 5 '17 at 8:48
  • Ok I understand. What's the field name of your lookup? – Martin Lezer Jan 5 '17 at 8:53
  • The lookup is ICIX_Product__r.L1dlF0rm0rg__Case__c from the ICIX_Product__c object the API name is L1dlF0rm0rg__Case__c, this is a lookup to the L1dlF0rm0rg__Case__c object referenceTo: L1dlF0rm0rg__Case__c relationshipName: L1dlF0rm0rg__Case__r soapType: tns:ID sortable: true type: reference – Jason Jan 5 '17 at 8:59
  • Ok. I edited my answer. This should work. – Martin Lezer Jan 5 '17 at 9:06
  • I appreciate your help, your answer works. I have marked it as the best answer. – Jason Jan 5 '17 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.