1

I do something wrong but have no idea what. The answers I found didn't help me. I'm new with salesforce, probably don't understand an obvious thing.

I'm creating print button in Visualforce, and wanted to list all related objects - employers enter image description here

So put the code:

<apex:pageBlock title="Employment">
  <apex:pageBlockTable value="{!CI_Candidate__c.Employment__r}" var="Employment">
    <apex:column value="{!Employment.CI_PRO_Account__c}"/> <apex:column value="{!Employment.Role__c}"/> 
    <apex:column value="{!Employment.Role_in_the_Company__c}"/> 
    <apex:column value="{!Employment.CI_PRO_Start_Date__c}"/>
    <apex:column value="{!Employment.CI_PRO_End_Date__c}"/>
  </apex:pageBlockTable>
</apex:pageBlock>

Error message:

Error: Invalid field Employment__r for SObject CI_Candidate__c

3
  • <apex:pageBlock title="Employment"> <apex:pageBlockTable value="{!CI_Candidate__c.Employment__r}" var="Employment"> <apex:column value="{!Employment.CI_PRO_Account__c}"/> <apex:column value="{!Employment.Role__c}"/> <apex:column value="{!Employment.Role_in_the_Company__c}"/> <apex:column value="{!Employment.CI_PRO_Start_Date__c}"/> <apex:column value="{!Employment.CI_PRO_End_Date__c}"/> </apex:pageBlockTable> </apex:pageBlock> – Artur Mikołajewski Apr 17 '18 at 14:05
  • 1
    It looks like you may have the wrong name for the relationship between CI_Candidate__c and the Employment object. Is Candidate the master and Employment the detail? – David Reed Apr 17 '18 at 14:11
  • Hi, I just want to print a candidate record with its child records - I'm trying to do Print CV button. Parent object name CI_Candidate, child object name Employment. I tried the same code wiht Activities - value="{!CI_Candidate__c.Tasks} and it worked perfectly. Don't understand why it doesn't work with the custom object – Artur Mikołajewski Apr 17 '18 at 15:09
0

The issue here is that you're using the wrong relationship name to access these child records. With custom objects, the relationship name is not just the name of the object or the plural of the name of the object, as it is in many cases with standard objects.

To find the relationship name, navigate to the lookup field that links the child object to the parent object. You'll find the relationship name defined there.

Then, in Visualforce, you can access child records with

<apex:pageBlockTable value="{!CI_Candidate__c.RELATIONSHIP_NAME__r}" var="Employment">

substituting in your relationship name.

3
  • Error: Invalid field Employment__r for SObject CI_Candidate__c – Artur Mikołajewski Apr 17 '18 at 15:20
  • sorry, didnt notice your comment – Artur Mikołajewski Apr 17 '18 at 15:22
  • Great - if the question is solved please consider accepting an answer. – David Reed Apr 17 '18 at 15:36
1

I am assuming you are trying to show children records on the page and I see that you have used CI_Candidate__c.Employment__r, which is not correct. This is a very good article where you will get to know how to show parent, child and grandchildren records on a custom VF page.

1
  • Hi, I just want to print a candidate record with its child records - I'm trying to do Print CV button. Parent object name CI_Candidate, child object name Employment. I tried the same code wiht Activities - value="{!CI_Candidate__c.Tasks} and it worked perfectly. Don't understand why it doesn't work with the custom object – Artur Mikołajewski Apr 17 '18 at 15:08

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.