You need to sign in to do that
Don't have an account?
KRay
Update Child Records using custom controller
Hey Forum,
I've created a visualforce page that displays a Parent(Parent__c) record with its only child record, Child__c. My goal is to allow the user to update the child record if needed. I'm able to display the child record but I've hit a road block when it comes to updating the child record. I've scaled the code back drastically but I'm unable to pass the values back to the controller. I've read on several sites , it says to pass the data to a class variable then update it but the NEW values aren't being passed. Can you help?
I've created a visualforce page that displays a Parent(Parent__c) record with its only child record, Child__c. My goal is to allow the user to update the child record if needed. I'm able to display the child record but I've hit a road block when it comes to updating the child record. I've scaled the code back drastically but I'm unable to pass the values back to the controller. I've read on several sites , it says to pass the data to a class variable then update it but the NEW values aren't being passed. Can you help?
public class UpdateTheChild{ public Parent__c Parent; public Child__c Child {get; set;} public Integer childAge {get; set;} public Id childId {get; set;} public String childDOB {get; set;} public void UpdateTheChild(ApexPages.standardController sc){ this.Parent = (Parent__c)sc.getRecord(); } public Parent__c getParent(){ return Parent; } public Child__c getChild(){ Child__c onlyChild = [Select ID, Name, Age, DOB from Child__c WHERE ParentId = :Opportunity.Id limit 1]; return onlyChild; } public PageReference UpdateChild(){ System.debug(Child); System.debug(childAge); System.debug(childDOB); //update Child; }
<apex:form> /** Parent will have page block here **/ <apex:pageBlock > <apex:pageBlockSection title="Child" columns="2" collapsible="false" showHeader="true"> <apex:outputField value="{!Child.Name}"/> <apex:InputField value="{!Child.Age}"/> <apex:InputField value="{!Child.DOB}"/> <apex:commandbutton action="{!updateChildRecord}" value="Update" rerender=""> <apex:param name="childAge" value=" {!Child.Age}" assignTo="{!childAge}"/> <apex:param name="childId" value=" {!Child.Id}" assignTo="{!childId}"/> <apex:param name="childDOB" value=" {!Child.DOB}" assignTo="{!childDOB}"/> </apex:commandbutton> </apex:pageBlockSection> </apex:PageBlock> <apex:form>
I have removed params. When you use inputField data will be binded. No need to use apex:param to pass values.
Can you please check once whether System.debug(Child); displays the values entered in page?
All Answers
I have removed params. When you use inputField data will be binded. No need to use apex:param to pass values.
Can you please check once whether System.debug(Child); displays the values entered in page?