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
sanjay dubey 19sanjay dubey 19 

Need to do standard button "save and new" functionality which will create contact from contact related list of account using visualforce page

my vf Page
vf Page



<apex:page controller="V2Controller" tabStyle="Contact">
<apex:form >
<apex:sectionHeader subtitle="New Contact" title="Contact Edit" description="Contacts not associated with accounts are private and cannot be viewed by other users or included in reports." help="https://help.salesforce.com/articleView?err=1&id=contacts_overview.htm&siteLang=en_US&ty...>
<apex:pageBlock title="Edit Contact" >
   <apex:pageBlockSection title="Contact Information" columns="2" onkeydown="1" collapsible="false">
       <apex:outputField value="{!contact.ownerid} "/>
       <apex:inputField value="{!contact.Phone}"/>
      
    <apex:pageBlockSectionItem >
        <apex:outputlabel value="First Name"/>
            <apex:outputpanel >
            <apex:inputfield value="{!Contact.Salutation}"/>
            &nbsp;
            <apex:inputfield value="{!Contact.FirstName}"/>
        </apex:outputpanel>
   </apex:pageBlockSectionItem>
       <apex:inputField value="{!contact.homephone}" />
       <apex:inputField value="{!contact.LastName}" required="true"/>
       <apex:inputField value="{!contact.MobilePhone}"/>
       <apex:inputField value="{!contact.Accountid}"/>
        <apex:inputField value="{!contact.otherphone}"/>
        <apex:inputField value="{!contact.Title}"/>
        <apex:inputField value="{!contact.fax}"/>
        <apex:inputField value="{!contact.Department}"/>
        <apex:inputField value="{!contact.Email}"/>
        <apex:inputField value="{!contact.Birthdate}"/>
       <apex:inputField value="{!contact.Assistantname}"/>
       <apex:inputField value="{!Contact.ReportsToId}"/>
       <apex:inputField value="{!contact.AssistantPhone}"/>
       <apex:inputField value="{!contact.LeadSource}"/>
      
      
      
      
   </apex:pageBlockSection>
   <apex:pageBlockSection columns="2" title="Address Information" collapsible="false">
       <apex:inputField value="{!contact.MailingStreet}"/>
       <apex:inputField value="{!contact.otherStreet}"/>
        
       <apex:inputField value="{!contact.MailingCity}"/>
       <apex:inputField value="{!contact.otherCity}"/>
      
       <apex:inputField value="{!contact.MailingState}"/>
       <apex:inputField value="{!contact.otherState}"/>
      
       <apex:inputField value="{!contact.MailingPostalCode}"/>
       <apex:inputField value="{!contact.otherPostalCode}"/>
      
       <apex:inputField value="{!contact.MailingCountry}"/>
       <apex:inputField value="{!contact.OtherCountry}"/>
      
      
   </apex:pageBlockSection>
  
  
   <apex:pageBlockSection title=" Additional Information" collapsible="false">
      
       <apex:inputField value="{!contact.Languages__c}"/>
       <apex:inputField value="{!contact.Level__c}"/>
  
   </apex:pageBlockSection>
  
     <apex:pageBlockSection title=" Description Information" collapsible="false" >
      
       <apex:inputTextarea value="{!contact.Description}" rows="7" cols="90"/>
   </apex:pageBlockSection>
   <apex:pageBlockButtons >
       <apex:commandButton value="Save" Action="{!save}"/>  
       <apex:commandButton value="Save & New" Action="{!SaveAndNew}"/>
       <apex:commandButton value="Cancel" Action="{!cancel}" immediate="true"/> 
   </apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>

My Controller class

public class V2Controller
{
    
  public Account acc=new account();
  public Contact contact{get;set;}
  
            public V2Controller()
            {
                acc=[select id,Billingcity,BillingStreet,BillingState,BillingCountry,BillingPostalCode,ShippingStreet,
                            ShippingCity,Shippingstate,ShippingPostalCode,Shippingcountry from account where id=:apexpages.currentpage().getparameters().get('id')];
                            
                    contact=new Contact();
                    contact.Mailingcity=acc.Billingcity;
                    contact.MailingStreet=acc.BillingStreet;
                    contact.MailingState=acc.BillingState;
                    contact.MailingPostalCode = acc.BillingPostalCode;
                    contact.Mailingcountry=acc.BillingCountry;
                    
                    contact.otherStreet = acc.ShippingStreet;
                    contact.otherCity= acc.ShippingCity;
                    contact.otherstate = acc.Shippingstate ;
                    contact.otherPostalCode = acc.ShippingPostalCode;
                    contact.othercountry = acc.Shippingcountry;  
                    contact.accountid=acc.id;
            }
            
            public PageReference save()
             {
                insert contact;
                 //   ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!'));
                    PageReference pg = new PageReference('/'+acc.Id);
                    pg.setRedirect(true);
                    return pg;        
                }
          
            public pagereference cancel()
            {
                    PageReference pg = new PageReference('/'+acc.Id);
                    pg.setRedirect(true);
                    return pg;
              }
              
               public Pagereference SaveAndNew()
            {
                   insert contact;
                   return null;
              }

}