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
miiWorksmiiWorks 

Native Filtered Lookup Causing Error in VF

Hello

 

I have a class which is being used to display a picklist (from a lookup type field), which has a filtered lookup resitrciton (an Id of another relationship must be the same as the child lookup to the parent). This is to ensure you can only select a product from that financier.

 

This works ok in native, however in VF i get this error

 

System.TypeException: Invalid conversion from runtime type SOBJECT:miiHomeLoan__Loan_Split__c to SOBJECT:miiHomeLoan__Loan_Product__c 


Class.ProductList.: line 5, column 1 

 

How am i able to replicate the lookup behaviour, and make sure the Id from the other field is being used in my class?

 

Here is my class

 

public class ProductList {

    private miiHomeLoan__Loan_Product__c loanproduct;
    public ProductList(ApexPages.StandardController controller) {
    this.loanproduct = (miiHomeLoan__Loan_Product__c)controller.getRecord();
    }
    public List <SelectOption> getLoanProduct {
    Get{
    List <SelectOption> loanproduct = new List <SelectOption>();
    
    for( miiHomeLoan__Loan_Product__c lp: [Select Name FROM miiHomeLoan__Loan_Product__c WHERE miiHomeLoan__Active__c = TRUE ]){
        loanproduct.add(new selectOption(lp.id, lp.Name));
    }
    return loanproduct;
    }
    Set;
    }
    }

 

Here is my VF

 

<apex:page showHeader="true" standardController="miiHomeLoan__Loan_Split__c" extensions="FunderList,ProductList" id="thePage">
    <apex:form id="theForm">
      <apex:sectionHeader title="Loan Split" subtitle="New Loan Split"/>  
        <apex:pageBlock title="New Loan Split">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Financier & Loan Application" columns="2" collapsible="false">
            
                   <apex:pageblockSectionItem >
                   <apex:outputLabel value="Financier"/>
                   <apex:ActionRegion >
                   <apex:selectList id="funder" value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Financier__c}" size="1" title="Financier" required="true" >
                   <apex:selectOptions value="{!getFunder}"/>
                       <apex:actionSupport event="onchange" status="StatusChange" rerender="informationcontainer"/>
                   </apex:selectList> 
                   <apex:actionStatus startText="Refreshing..." id="StatusChange"/>                          
                   </apex:ActionRegion>
                   </apex:pageblockSectionItem> 
            <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Application__c}" required="true" />
            </apex:pageBlockSection>
            <apex:outputPanel id="informationcontainer">
                   <apex:pageBlockSection title="Loan Product" columns="2" collapsible="false" id="information" rendered="{!IF(miiHomeLoan__Loan_Split__c.miiHomeLoan__Financier__c <> '', true, false)}">
                   <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Product__c}" required="true" />               
               </apex:pageBlockSection> 
            </apex:outputPanel>
            <apex:pageBlockSection title="Loan Product Details" collapsible="false">
                   <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Split_Amount_Dollars__c}" required="true" /> 
                   <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Split_Status__c}" required="true" />                                    
                   <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Repay_Type__c}" required="true" />
                   <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Account_Number__c}" required="false" />  
                   <apex:inputField value="{!miiHomeLoan__Loan_Split__c.Purpose__c}" required="true" /> 
                   <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Financier_Split_ID__c}" required="false" /> 
                   <apex:inputTextarea cols="40" value="{!miiHomeLoan__Loan_Split__c.Loan_Purpose_Note__c}" required="false" /> 
                   <apex:inputTextarea cols="40" value="{!miiHomeLoan__Loan_Split__c.Repayment_to_Come_From__c}" required="false" />                                      
                   <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Deduct_Term__c}" required="true" /> 
            </apex:pageBlockSection>                                                                                                                           
        </apex:pageBlock>
    </apex:form>    
</apex:page>

 

I think i have to store the id from the other field, and refernce it in my query, but im not sure how to do this. I do have this sample code but i couldnt get it to work

 

public class MilestoneList {

    private ApexPages.StandardController stdCtrl;
    
    public MilestoneList(ApexPages.StandardController controller)

    {

    stdCtrl=controller;

    }

    List<miiProject__Project_Milestone__c> myList;

    Public List<miiProject__Project_Milestone__c> getMilestoneList() {

myList = [SELECT Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, miiProject__Project__c, miiProject__Account_Name__c, miiProject__Active__c, miiProject__Contact_Name__c, miiProject__Date_Due__c, miiProject__Date_Time_Completed__c, miiProject__Date_Time_Started__c, miiProject__Description__c, miiProject__Is_Closed__c, miiProject__Project_Manager_Name__c, miiProject__Public__c, miiProject__Status__c, miiProject__Subject__c, miiProject__Actual_Hours_Completed__c, miiProject__Actual_Hours_Total__c, miiProject__Number_Of_Project_Tasks_Completed__c, miiProject__Number_Of_Project_Tasks__c, ID_Historic__c, Date_Created_Historic__c, Date_Signed_Off__c, Signed_Off__c, Date_Completed__c FROM miiProject__Project_Milestone__c WHERE miiProject__Project__c=:stdCtrl.getId() ORDER BY miiProject__Date_Due__c ASC ];

    /// ORDER BY CAN BE ASC OR DESC 

    return  myList;

    }

    public static testmethod void Test1()

    {

    miiProject__Project_Milestone__c p=new miiProject__Project_Milestone__c();

    ApexPages.StandardController sc = new ApexPages.standardController(p);

           

    MilestoneList Mil=new MilestoneList (sc);

    Mil.getMilestoneList();

    }     

}