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
gautamgautam 

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">
<tr>
<td>
<apex:form >
<apex:pageBlock title="Welcome For Registration" >

<apex:pageBlockSection title="Event Details">

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


<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:pageBlockSection>



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

</apex:page>

Arvind1Arvind1

Hi,

 

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
</apex:datatable>

 Thanks

Arvind

 

gautamgautam

I am still getting the error

 

 

Error: Invalid field Registrant__r for SObject Event__c
Arvind1Arvind1

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:form>
      <apex:dataTable value="{!A__c.B__r}" var="t">
      <apex:column>
      <apex:inputField value="{!t.name}"/>
      </apex:column>
      </apex:dataTable>
  </apex:form>
</apex:page>

 

Here A is parent and B is child

 

gautamgautam

Thanks for your reply ...it 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 ...

OnurKOnurK

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.

 

Event__c.Registrants__r