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
Varun TejaVarun Teja 

How to get and save account name to contact from saved account one VF page to another VF page

I'm trying to save account name to contact in VF page 2 which is saved account in VF page1.I count not able to save account name into contact. But contact is saving without account name.Please help me on this
Below is my code:

VF page1:
<apex:page standardController="Account" extensions="AccountSubmitPageController">
    <apex:form >
        <apex:pageBlock title="Insert Account  Record" id="pbAccountDetails">
            <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockSection >
                <apex:inputField value="{! Account.OwnerId }" />
                <apex:inputField value="{! Account.Name }" />
                <apex:inputField value="{! Account.Type }" />
                <apex:inputField value="{! Account.Industry }" />
                <apex:inputField value="{! Account.AnnualRevenue }" />
                <apex:inputField value="{! Account.NumberOfEmployees }" />
                <apex:inputField value="{! Account.Phone }" />
                <apex:inputField value="{! Account.Rating }" />
                <center><apex:commandButton action="{! save }" value="Save" /></center>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

VF page 2:

<apex:page standardController="Contact" extensions="AccountSubmitPageController">
    <apex:form >
        <apex:pageBlock title="Insert Contact  Record">
            <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockSection >
                <apex:outputText label="Account Name" value="{!$CurrentPage.parameters.accountName}" />
                <apex:inputField value="{! Contact.FirstName }" />
                <apex:inputField value="{! Contact.LastName }" />
                <apex:inputField value="{! Contact.Birthdate }" />
                <apex:inputField value="{! Contact.Description }" />
                <apex:inputField value="{! Contact.Email }" />
                <apex:inputField value="{! Contact.HomePhone }" />
                <apex:inputField value="{! Contact.Level__c }" />
                <apex:inputField id="total" value="{!Contact.Total_Contacts_Added_till_Now__c}" />
                
            </apex:pageBlockSection>
            <apex:pageblockButtons location="bottom">
                <apex:commandButton style="float:centre" action="{! addMoreContacts }" value="Add More Contacts" />
                <apex:commandButton style="float:centre" value="I don't want to create contact" />
                <apex:commandButton style="float:centre" value="Submit Contact's" />
            </apex:pageblockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller class:

 
Raj VakatiRaj Vakati
You could do it as below 
 
public class AccountSubmitPageController {
    public Account acct{get;set;}
    
    public AccountSubmitPageController(ApexPages.StandardController  sc){
        
    }
    
    public PageReference save(){
        
        insert acct ;
        
        return new PageReference('/apex/vfapge2?accId='+acct.Id);
    }
    
    
}
 
<apex:page standardController="Account" extensions="AccountSubmitPageController">
    <apex:form >
        <apex:pageBlock title="Insert Account  Record" id="pbAccountDetails">
            <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockSection >
                <apex:inputField value="{! acct.OwnerId }" />
                <apex:inputField value="{! acct.Name }" />
                <apex:inputField value="{! acct.Type }" />
                <apex:inputField value="{! acct.Industry }" />
                <apex:inputField value="{! acct.AnnualRevenue }" />
                <apex:inputField value="{! acct.NumberOfEmployees }" />
                <apex:inputField value="{! acct.Phone }" />
                <apex:inputField value="{! acct.Rating }" />
                <center><apex:commandButton action="{! save }" value="Save" /></center>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
Varun TejaVarun Teja
Thanks for reply..but here I'm saving contact records.Please check one more time