You need to sign in to do that
Don't have an account?
Dutta Sourav
Displaying Parent Object on Child Record through VF Page
I want to display the parent Object on Child Record where there is Master-Details relationship.
There are two Objects: Student(Child) & College (Parent).
I want to design a form in Visualforce to insert Student Details where I want to take College as input.
But, Its showing error.
Can anyone help?
See following description for master lookup field
Creates a special type of parent-child relationship between this object (the child, or "detail") and another object (the parent, or "master") where:
The relationship field allows users to click on a lookup icon to select a value from a popup list. The master object is the source of the values in the list.
All Answers
In your visualforce page simply use <apex:inputField/> attribute and give the proper value i.e the master detail field name.
Hi Sameer,
I have done that only. In that case only the field name is displaying.
It's not allowing to accept values.
what is the error you are getting ? Can you please share the code where you are getting errors.
Sameer,
Sharing the code:
VF Page:
<apex:page controller="recordstd">
<apex:form >
<apex:pageBlock title="New Record">
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!ssave}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information">
<apex:inputField value="{!sc.sname__c}" required="true"/>
<apex:inputField value="{!sc.College_Name__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public with sharing class recordstd {
public PageReference ssave() {
insert sc;
PageReference ref= new PageReference('/'+sc.id);
return ref;
}
public Student__c sc{get; set;}
}
The Displayed Error is:
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!ssave}' in component <apex:commandButton> in page controller2: Class.recordstd.ssave: line 5, column 1
Just add the constructor.
Add the following code .
public void recordstd(){
sc = new student__c () ;
}
happy coding ..
Still the error is showing. Problem is that the college field is not showing on the VF Page.
Further help is appreciated.
See following description for master lookup field
Creates a special type of parent-child relationship between this object (the child, or "detail") and another object (the parent, or "master") where:
The relationship field allows users to click on a lookup icon to select a value from a popup list. The master object is the source of the values in the list.