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
Adam LeeAdam Lee 

Help with saving a value

Hi all.

Hope you can help.

I've created a visualforce page of a custom object with ext controller but it would'n't save to the Contact (Master Detail).

I'm quite new to SF coding.

Here's the VF
 
<apex:page standardcontroller="Fact_Find__c" extensions="FactFindClass" tabstyle="Fact_Find__c">
<apex:form >   
<apex:sectionheader title="My Life Fact-Find"/>
    
<Apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!edit}" value="Edit"/>
</apex:pageBlockButtons>
    
<apex:pageBlocksection id="FFContact"  title="Contact" columns="2" collapsible="false" showheader="true">    
<apex:inputField value="{!ff.Contact__c}" label=""/>
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF"  title="Application Method" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="When you are away from the office and completing an application, which method do you usually use?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Application_Method__c}" label=""/>  
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF2"  title="Further Calls Required?" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="When you submit an application using an online system, without the customer present, how often do you usually have to call them back to gather additional information from when you originally met with them?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Callback_Question__c}" label=""/>  
</apex:pageBlocksection>
<apex:pageBlocksection id="FF3"  title="Mobile/Tablet" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="Would you find a mobile/ tablet version of OLPC useful?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Mobile_Tablet_Question__c}" label=""/>    
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF4"  title="Customer Broadband" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="If you don’t already, would you be comfortable using your customer’s broadband to complete an application online?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Customer_Broadband_Question__c}" label=""/> 
<apex:inputField value="{!Fact_Find__c.My_Life_Customer_Broadband_Question_Add__c}" label="Why?"/>
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF5"  title="Medical Questions" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="If you had the capability to “hand off” the medical questions to the customer so that they could complete them on their own and even at a different time, would you find this useful and appealing for your sales process and the customer journey?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Hand_Off_Medical_Questions__c}" label=""/> 
<apex:inputField value="{!Fact_Find__c.My_Life_Medical_Questions_A__c}" label="Why?" style="width:360px; height:40px"/> 
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF6"  title="Underwriting Answers" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="Would some customers like the option to prohibit you from seeing their underwriting answers?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Prohibit_U_W_Answers_Question__c}" label=""/>    
</apex:pageBlocksection>
</apex:pageBlock>
</apex:form>
</apex:page>

Here's the ext:
 
public with Sharing class FactFindClass {

    Public Contact con {get;set;}
    Public Contact FFContact {get;set;}
    Public Fact_Find__c ff {get; set;}
    
    public FactFindClass(ApexPages.StandardController sc){
        con = [Select ID, First_Last_Name__c from Contact limit 1];
    ff = [Select Id, Contact__c from Fact_Find__c limit 1];
        ff.Contact__c=con.Id;
    }
    
    
}


Can someone help?

Thanks in advance

Adam
Adam LeeAdam Lee
I tried to put this /apex/MyLifeFactFind?id={!Contact.Id} onto a custom button but it threw back 

Id value 003f000000ZOoqy is not valid for the Fact_Find__c standard controller
Abhishek BansalAbhishek Bansal
Hi Adam,

Please use the below controller class :
public with Sharing class FactFindClass {

    Public Contact con {get;set;}
    Public Contact FFContact {get;set;}
    Public Fact_Find__c ff {get; set;}
    
    public FactFindClass(ApexPages.StandardController sc){
        con = [Select ID, First_Last_Name__c from Contact limit 1];
        ff = (Fact_Find__c)sc.getRecord();
        ff.Contact__c = con.Id;
    }
    
    
}
Let me know if you have any issue in it.

Thanks,
Abhishek