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

Creating related records in visualforce page

Hi All,


I have two objects Event__C and Registrant__C .on Registrant object we hav a lookup field event link pointing to event object .


Now i have created a VF page on event object which i am displaying on site.

in this page the first part shows details of events using output field and the second part shows registrant object fields so that a site user can register for the event .But i am not able to do it properly .Please help me .


Getting error "


Error: Invalid field Registrant__r for SObject Event__c


Heres the code


<apex:page standardController="event__c" sidebar="false" showHeader="false" extensions="Registerbutton">

<table width="90%" align="center">
<apex:form >
<apex:pageBlock title="Welcome For Registration" >

<apex:pageBlockSection title="Event Details">

<apex:Outputfield value="{!Event__c.Name}"  />

<apex:pageBlockSection title="Guest Information" columns="2">
<apex:inputField value="{!Event__c.Registrant__r.First_Name__c}" />
<apex:inputField value="{!Event__c.Registrant__r.Last_Name__c}" />
<apex:inputField value="{!Event__c.Registrant__r.Company__c}" />
<apex:inputField value="{!Event__c.Registrant__r.Email__c}" />
<apex:inputField value="{!Event__c.Registrant__r.Phone__c}" />
<apex:inputField value="{!Event__c.Registrant__r.Address__c}" />

<apex:pageBlockButtons location="bottom" >
<apex:commandButton action="{!Register}" value="Register " />
<apex:image value="{!$Resource.elephant1}" width="100%" height="50%" />





Since you are trying to display the related list, you have to use that in a datatable or pageblocktable

for iteration i think


Try to use the same in datatable



<apex:datatable value="{!Event__c.Registrant__r}" var="evereg">
<apex:column value="{!evereg.Name}"/>
give all the fields as above





I am still getting the error



Error: Invalid field Registrant__r for SObject Event__c

Can you please check the Registrant object name once.

Because I am able to save the code which I posted without any error. But when I give some other name for

the child object, I am getting the same error as you are getting


My object names are : A, B


I am using the following code:

<apex:page standardController="A__c">
      <apex:dataTable value="{!A__c.B__r}" var="t">
      <apex:inputField value="{!}"/>


Here A is parent and B is child



Thanks for your reply works now and displays child records..


But my requirement is to create child records ....not display the existing one ...

How can i achieve this ...please help me ...


If you have two objects Event__C and Registrant__C and Registrant__c is the child, you need to use pulural object for the related one. Try using this way.