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
HarryHHHarryHH 

How to reference a costum controller Field that is part of a lookup

Hello,

 

I have an orderposition that is referenced in a quotationposition. I now want to reference fields in the according orderposition.

In my VF page I tried to reference the following:

...

       <apex:dataTable value="{!KV_Positionen}" var="KP" id="Table" styleClass="my_table">
            <apex:facet name="header"></apex:facet>
            <apex:column >
                <apex:facet name="header">Anzahl</apex:facet>
                <apex:Outputtext value="{!KP.Auftragspositionen__c.GenAnzVerp__c}"/>
            </apex:column>

...

 

Auftragspositionen__c (orderposition) is a lookup in KV_Positionen (quotationposition).

 

My controller looks like:

...

                        KV_Positionen = [select name, KVA__c, Artikel__c, Auftragsposition__c, Verkaufspreis__c,
                                                        MWSt_1__c, MWSt_2__c, KK_Preis__c, gesetzl_zuzahlung__c, wirtschaftl_zuzahlung__c
                                                        from KVA_Position__c where Auftragsposition__c = :Apos.Id];

...

public KVA_Position__c[] getKV_Positionen()
{
                system.debug ('KV_pos: ' + KV_Positionen);
                return KV_Positionen;
}

 

I always get the error

Invalid field Auftragspositionen__c for SObject KVA_Position__c

 

If I try it with Auftragspositionen__r I get also an error.

 

Thanks in advance

Harry

Best Answer chosen by Admin (Salesforce Developers) 
DharmeshDharmesh

I think this because you didnt query for field GenAnzVerp__c. You have to add this field in select query as like

 

KV_Positionen = [select name, KVA__c, Artikel__c, Auftragsposition__c,Auftragsposition__r.GenAnzVerp__c, Verkaufspreis__c,
                                                        MWSt_1__c, MWSt_2__c, KK_Preis__c, gesetzl_zuzahlung__c, wirtschaftl_zuzahlung__c
                                                        from KVA_Position__c where Auftragsposition__c = :Apos.Id];

 

 

and in VF

 

<apex:Outputtext value="{!KP.Auftragspositionen__r.GenAnzVerp__c}"/>

All Answers

DharmeshDharmesh

I think this because you didnt query for field GenAnzVerp__c. You have to add this field in select query as like

 

KV_Positionen = [select name, KVA__c, Artikel__c, Auftragsposition__c,Auftragsposition__r.GenAnzVerp__c, Verkaufspreis__c,
                                                        MWSt_1__c, MWSt_2__c, KK_Preis__c, gesetzl_zuzahlung__c, wirtschaftl_zuzahlung__c
                                                        from KVA_Position__c where Auftragsposition__c = :Apos.Id];

 

 

and in VF

 

<apex:Outputtext value="{!KP.Auftragspositionen__r.GenAnzVerp__c}"/>

This was selected as the best answer
SSRS2SSRS2

I agree with Dharmesh sample but simple mistake in VF code stuff 

    <apex:Outputtext value="{!KP.Auftragspositionen__r.GenAnzVerp__c}"/>

need to be changed 

 

<apex:Outputtext value="{!KP.Auftragsposition__r.GenAnzVerp__c}"/>

 -Suresh

 

HarryHHHarryHH

Hi Darmesh,

 

thanks, that works!

 

Harry

HarryHHHarryHH

Hi Suresh,

 

thanks for the correction!

 

Harry