Find your content:

Search form

You are here

How to polulate Child object field from a VF page standard controller of the Master Object

 
Share

have a Visual force page that overrides the "Close Case button" on case details page.VF page uses case standardController.I want to populate CaseComment.commentbody field of the from this VF page. CaseComment is a Child object of Case.Sample code is as below

<apex:page standardController="Case"> <apex:form> <apex:inputField value="{!Case.Postback_Options__c}" /> <apex:inputField value="{!CaseComment.CommentBody}" label="Internal Comments" /> </apex:form> </apex:page>

This throws an error Unknown property 'CaseStandardController.CaseComment'

Can Somebody please help me out.


Attribution to: user7533

Possible Suggestion/Solution #1

CaseComment is separate object in salesforce. So I suggest you use either standard controller extension or custom controller.

But If you want or have to use only standard controller here is some code:

<apex:page standardController="Case">
   <apex:form>
       <apex:repeat value="{!Case.CaseComments}" var = "cc">
           <apex:inputField value="{!cc.CommentBody}" label="Internal Comments" />
       </apex:repeat>
   </apex:form>
</apex:page> 

Attribution to: Artur Kępczyński

Possible Suggestion/Solution #2

<apex:inputField> can only be used with SObject fields as per the documentation. Your Case.CaseComments returning a List. So you have to iterate through the list to access child fields.

<apex:repeat value="{!Case.CaseComments}" var = "child">
    <apex:inputField value="{!child.CommentBody}" label="Internal Comments" />
</apex:repeat>

NOTE: Make sure to check the child relationship name in the WSDL for safe side.


Attribution to: highfive
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30856

My Block Status

My Block Content