0

I have a relatively simple VF page that is launched from a button on a custom object called 'Inclusion_detail__c. The page uses the standard Controller and is effectively a data entry form for specific fields which works perfectly from fields on the Inclusion_detail__c object. I want to extend this to add a field from the parent Contact record which is a master-detail relationship. The field renders perfectly, but when I press Save, the parent fields do not update. Can this be achieved with a standard controller or do I need an extension? Do I need to pass in the Contact parameter somewhere?

<apex:page standardController="Inclusion_Details__c">
<apex:pageMessages />
<h1 style="font-size:200%;"><font color="#0000ff" text-align="center"><b>Hello {!$User.FirstName}</b></font></h1> Please enter the MASI infromation for <b> {!Inclusion_Details__c.Contact__r.Name} </b><br></br><br></br>
<apex:form >
    <apex:pageBlock title="Enter MASI">
        <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="Cancel" action="{!cancel}"/>                
        </apex:pageBlockButtons>


        <apex:pageblockSection title="Consent" >
            <apex:inputfield value="{!Inclusion_Details__c.Contact__r.Agree_to_main_consent_statement__c}"/>          
            <apex:inputfield value="{!Inclusion_Details__c.Contact__r.Team__c}"/>          
        </apex:pageblockSection>


        <apex:pageblockSection title="Legal Guardian" > 
            <apex:inputText value="{!Inclusion_Details__c.Are_you_the_legal_guardian__c}"/>            
            <apex:inputField value="{!Inclusion_Details__c.Name_of_legal_guardian__c}"/>            
            <apex:inputField value="{!Inclusion_Details__c.Address_of_legal_guardian__c}"/>            
            <apex:inputField value="{!Inclusion_Details__c.Legal_guardian_call_back_time__c}"/>            
            <apex:inputField value="{!Inclusion_Details__c.Further_info_on_legal_guardian__c}"/>            
            <apex:inputField value="{!Inclusion_Details__c.Legal_Guardian_Telephone__c}"/>            
        </apex:pageblockSection>
    </apex:pageBlock>
</apex:form>

Thanks

0

The problem is that you want to update Contact record using update action on the Inclusion_Details__c sobject. Standard Controller can't actually know about related Parent (Contact). So, you need to create an Extension for this controller and override save method where you can update contact separately like so:

Contact con = Inclusion_Details__r.Contact__r;
update con;

or you can add Inclusion_Details__c and Contact records to generic List - List<SObject> and update them in the one DML statement:

List<SObject> recordsToUpadte = new List<SObject>{
   inclusion,
   con
}
update recordsToUpdate;
0

You need a controller extension to update the record. It cannot be achieved through StandardController as per my understanding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.