You need to sign in to do that
Don't have an account?
Roc Suo
Invalid field for SObject in a Visualforce page
Hi
I am trying to build a table of data in a page to show the list of policies details from the Account. Policy__c is the Custom Object.
However, it always show "Invalid field Policy__c for SObject Account.
I did try to modify <apex:pageBlockTable value="{! Account.Policy__c}" var="Policy"> to <apex:pageBlockTable value="{! Account.Policy__r}" var="Policy">, it doesn't work. the error message became "Invalid field Policy__r for SObject Account.
How can I access the Custom Object from Standard Object? Thanks.
.
I am trying to build a table of data in a page to show the list of policies details from the Account. Policy__c is the Custom Object.
However, it always show "Invalid field Policy__c for SObject Account.
I did try to modify <apex:pageBlockTable value="{! Account.Policy__c}" var="Policy"> to <apex:pageBlockTable value="{! Account.Policy__r}" var="Policy">, it doesn't work. the error message became "Invalid field Policy__r for SObject Account.
How can I access the Custom Object from Standard Object? Thanks.
.
<apex:page sidebar="false" standardController="Account"> <apex:pageBlock title="Policy Detials"> <apex:pageBlockTable value="{! Account.Policy__c}" var="Policy"> <apex:column value="{! Policy.Insurance_Company__c}"/> <apex:column value="{! Policy.Name}"/> <apex:column value="{! Policy.Commencement_Date__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Append __r to that name and you should be good (my guess is it's called Policies__r)
All Answers
Append __r to that name and you should be good (my guess is it's called Policies__r)
<apex:page sidebar="false" standardController="Account">
<apex:pageBlock title="Policy Detials">
<apex:pageBlockTable value="{! Account}" var="Policy">
<apex:column value="{! Policy__r.Insurance_Company__c}"/>
<apex:column value="{! Policy__r.Name}"/>
<apex:column value="{! Policy__r.Commencement_Date__c}"/>
</apex:pageBlockTable>
</apex:pageBlock> </apex:page>
Actually the pageblocktable contains the object not the field.
Please mark the answer if it works.
Please use child Realtionship name with __r in this case As you are Trying to reference one to many Relationship of Acount to Policy__c object.
What I can realise you have lookup( or master deatil) of account object in policy__C object. in that case to refer all the policies of a single account you have to Use child relationship name with appended __r. its same like we user account.contacts to reference all the contact of a single account.
Let me Know if you need more help. mark it as solved by selecting it best answer. if it fixes the issue
https://qas-shared-assets.s3.amazonaws.com/snaps/tws891g1igytlnm
When I changed to <apex:pageBlockTable value="{! Account.Policies__r}" var="Policy">, problem sort.
What a stupid mistake I have! Thanks for your help.
At some point, we all did this same mistake. :)
thing to remember is for one to many relationship use child relationship Name with __r and for one to one relationship use object name with __r notation.
Thanks :)
I am experiencing a kind of similar problem and tried following the above mentioned steps as well but no luck.
Here is the case:
In my org there are 2 custom objects; 1. Potential Match 2. Incoming Associate Record.
There is a lookup relationship between these two.
Now I am trying to create a VF page on Potential Match so that I can bring "Qualified to Lead" ( a field on Incoming Associate Record) on Potential Match Lightning Page Layout.
I tried writing apex class as below and its showing this error.
Below is the relationship details of potential match and incoming associate record.
Any help will be highly regarded.
Thanks in advance