1

****VisualForce Page:****

<apex:page standardController="contact" extensions="contact1">
    <apex:form id="frm">

        <apex:pageBlock >
        <style>

            body .bPageBlock .pbBody .red .pbSubheader{

                background-color:#c1cdcd;

            }

            body .bPageBlock .pbBody .grey .pbSubheader{
                background-color:#c0c0c0;
            }
            body .bPageBlock .pbBody .grey .pbSubheader h3{
                color:#000;
            }
            p  {
    color: Black;
    font-family: Times New Roman;
    font-size: 160%;
    div {
    font-weight:bold;
}
        </style>

              <p><b>Doctor Details</b></p>
              <br/>
                <apex:pageBlockSection title="Personal Information" collapsible="false">
                           <apex:inputField value="{!objcontact.Salutation}"/><br/>
                           <apex:inputField value="{!objcontact.FirstName}"/>
                           <apex:inputField value="{!objcontact.LastName}"/>
                           <apex:inputField value="{!objcontact.MailingStreet}"/>
                           <apex:inputField value="{!objcontact.MailingCity}"/>
                           <apex:inputField value="{!objcontact.MailingState}"/>
                           <apex:inputField value="{!objcontact.MobilePhone}"/> 
                           <apex:inputField value="{!objcontact.Email}"/>

                          </apex:pageBlockSection>  
                         <apex:pageBlockSection title="Professional Information" collapsible="false"> 

                             <apex:inputField value="{!objcontact.Qualification__c}"/>
                             <apex:inputField value="{!objcontact.Specialization_Field__c}"/>
                             <apex:inputField value="{!objcontact.Years_of_Experience__c}"/>
                             <apex:inputField value="{!objcontact.Last_visit__c}"/>  
                        </apex:pageBlockSection>  

             <apex:pageBlockButtons >
                            <apex:commandButton value="Save" action="{!save}"/> 
                            <apex:commandButton action="{!cancel}" value="Cancel"/>    
             </apex:pageBlockButtons>     
         </apex:pageBlock>
    </apex:form>
</apex:page>

Controller

public with sharing class contact1
 { 
   public contact objcontact{get;set;}  
   public String Email { get; set; } 
   public String  conId { get; set; } 
   public List<contact> con { get; set; } 
   public boolean x{get;set;}   
   public String conname { get; set; } 
     public String conEmail { get; set; }    
            public contact1(ApexPages.StandardController controller)
             {   
              objcontact=new contact();  
               x=false;
               system.debug('`````````'+x);        }  
            public void save() 
                {           
                   con=[select email from contact];     
                      System.debug('1111111111111'+con);  
                      Email=objcontact.Email;   
                      System.debug('1111111111111'+Email);    
                              insert objcontact;
                                PageReference newocp = new PageReference('/apex/VFPage1?conId= contact.Id');
                              newocp.setRedirect(True);
                               system.debug('????????'+x);    } 
                                }  



     //pagereference pr = new pagereference('/'+objcontact.id);                          
              //return ;
3
  • 1
    have you tried return new pagereference('/'+objcontact.id); ? what is your exact issue. ?
    – Ratan Paul
    Commented Jan 13, 2016 at 9:34
  • What is the problem? Commented Jan 13, 2016 at 9:35
  • when i click save button the contact is saved but remains on same page and i want to redirect it to contacts tab where the contact gets stored
    – nikita
    Commented Jan 13, 2016 at 9:49

1 Answer 1

1

update your save method return type to Pagereference

public pagereference save() {
   //codes here

  return new pagereference('/'+objcontact.id);

}
1
  • @nikita Most welcome..
    – Ratan Paul
    Commented Jan 13, 2016 at 10:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .