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
Luke GreenstreetLuke Greenstreet 

Saving from Custom VF Page to Person Account

Hi,

I am new to visualforce and using a address QAS tool, to get this to function as we want I have had to put it on a VF page.

The VF page is accessed via the Person Account object when the related list NEW OVERRIDE button is pressed. The page works as intended but I dont know how to store the ID of the Person Account record that I came from. Do I need to use a custom controller? I have done some reading on apex:param and URL param but I am struggling to get my head around them. Any help would be much appreciated. Thanks

VF Page:
<apex:page standardController="Previous_Address__c" showHeader="true" recordSetVar="PreviousAdresses">
    
    <apex:form >      
            <apex:pageBlock mode="edit" title="Previous Address">
                    <apex:pageBlockButtons >
                        <apex:commandButton value="Save" action="{!Save}"/>
                        <apex:commandButton value="Cancel" action="{!Cancel}"/>
                    </apex:pageBlockButtons>
                <apex:pageBlockSection title="Previous Address" collapsible="false"  columns="1" >
                    <apex:outputField label="Contact" value="{!Previous_Address__c.Contact__c}"/> 
                    <apex:inputField Label="Address Resident From" value="{!Previous_Address__c.Address_Resident_From_Date__c}"/>
                    <apex:inputField Label="Address Resident To" value="{!Previous_Address__c.Address_Resident_To_Date__c}"/>                       
                    <apex:inputField Label="House Number" value="{!Previous_Address__c.House_Flat_No__c}"/>
                    <apex:inputField Label="House Name" value="{!Previous_Address__c.House_Name__c}"/>
                    <apex:inputField Label="Flat Number" value="{!Previous_Address__c.Flat_Number__c}"/>
                    <pca:Address Street="{!Previous_Address__c.Street__c}" State="{!Previous_Address__c.County__c}" City="{!Previous_Address__c.City__c}" Zip="{!Previous_Address__c.Postcode__c}" Country="{!Previous_Address__c.Country__c}"  > </pca:Address>            
                </apex:pageBlockSection>                     
             </apex:pageBlock> 
        </apex:form>        
</apex:page>

 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Luke,

As you mentioned you need to get the id, can you try checking if this works ApexPages.currentPage().getParameters().get('id') I found this was useful for getting the id from the URL.

Let me know if this helps.

Regards,
Anutej
Abhishek BansalAbhishek Bansal
Hi Luke,

Since this vf page is invoked from the related list of the person account page, that means the person account is a parent to the previous address object. You can simply use this statement to get the id of the parent person account:
<apex:outputField  value="{!Previous_Address__c.Person_Account__c}"/>
Please replace the Person_Account__c with the actual API name of the parent field.

Thanks,
Abhishek Bansal.
Luke GreenstreetLuke Greenstreet
Hi Both, first of all thank you so much for your responses, i really appreciate the help :). Unfortunately I have had no luck with your suggestions, maybe through poor execution by myself. I have repsonded to you both below.

Thanks again

Antuej:

where would i put that in the page? Like the below i get the following error "Element type "ApexPages.currentPage" must be followed by either attribute specifications, ">" or "/>"."

<apex:page standardController="Previous_Address__c" showHeader="true" recordSetVar="PreviousAdresses">
    <ApexPages.currentPage().getParameters().get('id')/>
    <apex:form >      
            <apex:pageBlock mode="edit" title="Previous Address">
                    <apex:pageBlockButtons >
                        <apex:commandButton value="Save" action="{!Save}"/>
                        <apex:commandButton value="Cancel" action="{!Cancel}"/>
                    </apex:pageBlockButtons>
                <apex:pageBlockSection title="Previous Address" collapsible="false"  columns="1" >
                    <apex:outputField label="Contact" value="{!Previous_Address__c.Contact__c}"/> 
                    <apex:inputField Label="Address Resident From" value="{!Previous_Address__c.Address_Resident_From_Date__c}"/>
                    <apex:inputField Label="Address Resident To" value="{!Previous_Address__c.Address_Resident_To_Date__c}"/>                       
                    <apex:inputField Label="House Number" value="{!Previous_Address__c.House_Flat_No__c}"/>
                    <apex:inputField Label="House Name" value="{!Previous_Address__c.House_Name__c}"/>
                    <apex:inputField Label="Flat Number" value="{!Previous_Address__c.Flat_Number__c}"/>
                    <pca:Address Street="{!Previous_Address__c.Street__c}" State="{!Previous_Address__c.County__c}" City="{!Previous_Address__c.City__c}" Zip="{!Previous_Address__c.Postcode__c}" Country="{!Previous_Address__c.Country__c}"  > </pca:Address>            
                </apex:pageBlockSection>                     
             </apex:pageBlock> 
        </apex:form>        
    </apex:page>


Abishek:

I tried switching out the output fields and recieved the following error. "Could not resolve field 'Person_Account__c' from <apex:outputField> value binding '{!Previous_Address__c.Person_Account__c}' in page NewPreviousAddressOverride"

<apex:page standardController="Previous_Address__c" showHeader="true" recordSetVar="PreviousAdresses">
    <apex:form >      
            <apex:pageBlock mode="edit" title="Previous Address">
                    <apex:pageBlockButtons >
                        <apex:commandButton value="Save" action="{!Save}"/>
                        <apex:commandButton value="Cancel" action="{!Cancel}"/>
                    </apex:pageBlockButtons>
                <apex:pageBlockSection title="Previous Address" collapsible="false"  columns="1" >
                    <apex:outputField  value="{!Previous_Address__c.Person_Account__c}"/>
                    <apex:inputField Label="Address Resident From" value="{!Previous_Address__c.Address_Resident_From_Date__c}"/>
                    <apex:inputField Label="Address Resident To" value="{!Previous_Address__c.Address_Resident_To_Date__c}"/>                       
                    <apex:inputField Label="House Number" value="{!Previous_Address__c.House_Flat_No__c}"/>
                    <apex:inputField Label="House Name" value="{!Previous_Address__c.House_Name__c}"/>
                    <apex:inputField Label="Flat Number" value="{!Previous_Address__c.Flat_Number__c}"/>
                    <pca:Address Street="{!Previous_Address__c.Street__c}" State="{!Previous_Address__c.County__c}" City="{!Previous_Address__c.City__c}" Zip="{!Previous_Address__c.Postcode__c}" Country="{!Previous_Address__c.Country__c}"  > </pca:Address>            
                </apex:pageBlockSection>                     
             </apex:pageBlock> 
        </apex:form>        
    </apex:page>
Abhishek BansalAbhishek Bansal
Hi Luke, 

Please use the API name of the field that stores the person account value on the previous address object. There should be a lookup field on address object, please use the API name of that field instead of Person_Account__c

Thanks,
Abhishek Bansal.
Luke GreenstreetLuke Greenstreet
Hi Abishek,

Apologies, this line <apex:outputField label="Contact" value="{!Previous_Address__c.Contact__c}"/>  is the master detail relationship link. however it is always greyed out when i load a new page with no value in.

My page is launched from the person account "Previous Address" related list.

Thanks

 
Abhishek BansalAbhishek Bansal
Hi Luke,

I don't understand what you are trying to say here. If possible please contact me on
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790

We can connect on a call and sort this out.

Thanks,
Abhishek Bansal