+ Start a Discussion
John BraunJohn Braun 

How to display "record successfully saved" in visualforce?

Hello,
I'm not a developer but have tried to create a visualforce page, that uses a standard controller, that inserts a record. The record inserted is master-detail to the opportunity object in SFDC.

The VF page works and saves the record as desired but I'd like to display a message to the end user that says, "Record Successfully Saved".

I'm afraid I need to create a controller extension to to this, which I do not know how to do. AND, if I have write a controller extension, I'll also have to write a test class, which I also do not know how to do.

Is this a basic request, and if so, could someone help me create the controller extension and test class? Please see below my VF page:


<apex:page standardcontroller="Customer_Survey__c">

<apex:form >
       
 
<apex:pageBlock title="Customer Survey" mode="edit">
      <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save"/>
        <apex:commandButton action="{!cancel}" value="Cancel"/>
      </apex:pageBlockButtons>
     
      <apex:pageBlockSection title="General" columns="2">
      <apex:inputField value="{!Customer_Survey__c.Opportunity_Name__c}"/>  
      <apex:outputField value="{!Customer_Survey__c.Client__c}"/>
      <apex:outputField value="{!Customer_Survey__c.Opportunity_Owner__c}"/>
      <apex:outputField value="{!Customer_Survey__c.Site__c}"/>
      <apex:outputField value="{!Customer_Survey__c.Close_Date__c}"/>
      <apex:outputField value="{!Customer_Survey__c.CreatedDate}"/>
     
       </apex:pageBlockSection>
     
      <apex:pageBlockSection title="Questions" columns="2">
     
 
     
        <apex:selectList value="{!Customer_Survey__c.Question_1__c}" multiselect="false" size="1"
                label="1.  How important was it to choose a vendor that could take your product through development to commercialization?">
         <apex:selectOption itemValue="--Select Option--" itemLabel="--Select Option--"/>
         <apex:selectOption itemValue="Not at all" itemLabel="1-Not at all"/>
         <apex:selectOption itemValue="Somewhat" itemLabel="2-Somewhat"/>
         <apex:selectOption itemValue="Average" itemLabel="3-Average"/>
         <apex:selectOption itemValue="High" itemLabel="4-High"/>
         <apex:selectOption itemValue="Critical" itemLabel="5-Critical"/>
         <apex:selectOption itemValue="N/A" itemLabel="Not Applicable"/>
      </apex:selectList>
     
    
     
      <apex:selectList value="{!Customer_Survey__c.Question_2__c}" multiselect="false" size="1"
                label="2.  Please rate how your prior experience working with Patheon in the past was an important factor in your decision, if applicable?">
         <apex:selectOption itemValue="--Select Option--" itemLabel="--Select Option--"/>
         <apex:selectOption itemValue="Not at all" itemLabel="1-Not at all"/>
         <apex:selectOption itemValue="Somewhat" itemLabel="2-Somewhat"/>
         <apex:selectOption itemValue="Average" itemLabel="3-Average"/>
         <apex:selectOption itemValue="High" itemLabel="4-High"/>
         <apex:selectOption itemValue="Critical" itemLabel="5-Critical"/>
         <apex:selectOption itemValue="N/A" itemLabel="Not Applicable"/>
      </apex:selectList>
     
     
     
      <apex:selectList value="{!Customer_Survey__c.Question_3__c}" multiselect="false" size="1"
                label="3.  How easy was it to reach Patheon with your original request? ">
         <apex:selectOption itemValue="--Select Option--" itemLabel="--Select Option--"/>
         <apex:selectOption itemValue="Difficult" itemLabel="1-Difficult"/>
         <apex:selectOption itemValue="Not Easy" itemLabel="2-Not Easy"/>
         <apex:selectOption itemValue="Average" itemLabel="3-Average"/>
         <apex:selectOption itemValue="Easy" itemLabel="4-Easy"/>
         <apex:selectOption itemValue="Very Easy" itemLabel="5-Very Easy"/>
         <apex:selectOption itemValue="N/A" itemLabel="Not Applicable"/>
      </apex:selectList>
     
     
     
       <apex:selectList value="{!Customer_Survey__c.Question_4__c}" multiselect="false" size="1"
                label="4.  How was our CDA process?">
         <apex:selectOption itemValue="--Select Option--" itemLabel="--Select Option--"/>
         <apex:selectOption itemValue="Poor" itemLabel="1-Poor"/>
         <apex:selectOption itemValue="Below Average" itemLabel="2-Below Average"/>
         <apex:selectOption itemValue="Acceptable" itemLabel="3-Acceptable"/>
         <apex:selectOption itemValue="Good" itemLabel="4-Good"/>
         <apex:selectOption itemValue="Excellent" itemLabel="5-Excellent"/>
         <apex:selectOption itemValue="N/A" itemLabel="Not Applicable"/>
      </apex:selectList>
     
     
     
      <apex:selectList value="{!Customer_Survey__c.Question_5__c}" multiselect="false" size="1"
                label="5.  How accurate were we in translating your RFP/project requirements into a formal proposal?">
         <apex:selectOption itemValue="--Select Option--" itemLabel="--Select Option--"/>
         <apex:selectOption itemValue="Poor" itemLabel="1-Poor"/>
         <apex:selectOption itemValue="Below Average" itemLabel="2-Below Average"/>
         <apex:selectOption itemValue="Acceptable" itemLabel="3-Acceptable"/>
         <apex:selectOption itemValue="Good" itemLabel="4-Good"/>
         <apex:selectOption itemValue="Excellent" itemLabel="5-Excellent"/>
         <apex:selectOption itemValue="N/A" itemLabel="Not Applicable"/>
      </apex:selectList>
     
    
     
      <apex:selectList value="{!Customer_Survey__c.Question_6__c}" multiselect="false" size="1"
                label="6.  How much did our proposal and subsequent revision turnaround time influence your vendor selection decision?">
         <apex:selectOption itemValue="--Select Option--" itemLabel="--Select Option--"/>
         <apex:selectOption itemValue="Not at all" itemLabel="1-Not at all"/>
         <apex:selectOption itemValue="Somewhat" itemLabel="2-Somewhat"/>
         <apex:selectOption itemValue="Average" itemLabel="3-Average"/>
         <apex:selectOption itemValue="High" itemLabel="4-High"/>
         <apex:selectOption itemValue="Critical" itemLabel="5-Critical"/>
         <apex:selectOption itemValue="N/A" itemLabel="Not Applicable"/>
      </apex:selectList>
     
     
     
      <apex:selectList value="{!Customer_Survey__c.Question_7__c}" multiselect="false" size="1"
                label="7.  How large a factor was facility location in making your final decision?">
         <apex:selectOption itemValue="--Select Option--" itemLabel="--Select Option--"/>
         <apex:selectOption itemValue="Not at all" itemLabel="1-Not at all"/>
         <apex:selectOption itemValue="Somewhat" itemLabel="2-Somewhat"/>
         <apex:selectOption itemValue="Average" itemLabel="3-Average"/>
         <apex:selectOption itemValue="High" itemLabel="4-High"/>
         <apex:selectOption itemValue="Critical" itemLabel="5-Critical"/>
         <apex:selectOption itemValue="N/A" itemLabel="Not Applicable"/>
      </apex:selectList>
     
    
     
      <apex:selectList value="{!Customer_Survey__c.Question_8__c}" multiselect="false" size="1"
                label="8.  How important was the site qualification/technical visit in your vendor selection?">
         <apex:selectOption itemValue="--Select Option--" itemLabel="--Select Option--"/>
         <apex:selectOption itemValue="Not at all" itemLabel="1-Not at all"/>
         <apex:selectOption itemValue="Somewhat" itemLabel="2-Somewhat"/>
         <apex:selectOption itemValue="Average" itemLabel="3-Average"/>
         <apex:selectOption itemValue="High" itemLabel="4-High"/>
         <apex:selectOption itemValue="Critical" itemLabel="5-Critical"/>
         <apex:selectOption itemValue="N/A" itemLabel="Not Applicable"/>
      </apex:selectList>
     
    
     
      <apex:selectList value="{!Customer_Survey__c.Question_9__c}" multiselect="false" size="1"
                label="9.  Please rate how important Patheon’s regulatory history was in making your final decision?">
         <apex:selectOption itemValue="--Select Option--" itemLabel="--Select Option--"/>
         <apex:selectOption itemValue="Not at all" itemLabel="1-Not at all"/>
         <apex:selectOption itemValue="Somewhat" itemLabel="2-Somewhat"/>
         <apex:selectOption itemValue="Average" itemLabel="3-Average"/>
         <apex:selectOption itemValue="High" itemLabel="4-High"/>
         <apex:selectOption itemValue="Critical" itemLabel="5-Critical"/>
         <apex:selectOption itemValue="N/A" itemLabel="Not Applicable"/>
      </apex:selectList>
     
     
      <apex:selectList value="{!Customer_Survey__c.Question_10__c}" multiselect="false" size="1"
                label="10.  Please rate how important price was when making your final vendor selection?">
         <apex:selectOption itemValue="--Select Option--" itemLabel="--Select Option--"/>
         <apex:selectOption itemValue="Not at all" itemLabel="1-Not at all"/>
         <apex:selectOption itemValue="Somewhat" itemLabel="2-Somewhat"/>
         <apex:selectOption itemValue="Average" itemLabel="3-Average"/>
         <apex:selectOption itemValue="High" itemLabel="4-High"/>
         <apex:selectOption itemValue="Critical" itemLabel="5-Critical"/>
         <apex:selectOption itemValue="N/A" itemLabel="Not Applicable"/>
      </apex:selectList>
     
      <apex:selectList value="{!Customer_Survey__c.Question_11__c}" multiselect="false" size="1"
                label="11.  Please rate the negotiation process for legal terms and conditions?">
         <apex:selectOption itemValue="--Select Option--" itemLabel="--Select Option--"/>
         <apex:selectOption itemValue="Poor" itemLabel="1-Poor"/>
         <apex:selectOption itemValue="Below Average" itemLabel="2-Below Average"/>
         <apex:selectOption itemValue="Acceptable" itemLabel="3-Acceptable"/>
         <apex:selectOption itemValue="Good" itemLabel="4-Good"/>
         <apex:selectOption itemValue="Excellent" itemLabel="5-Excellent"/>
         <apex:selectOption itemValue="N/A" itemLabel="Not Applicable"/>
      </apex:selectList>
     
      <br></br>
      <br></br>
      <br></br>
     
      <apex:inputField value="{!Customer_Survey__c.Feedback_Comments_Process_Improvements__c}"/>

  </apex:pageblocksection>

 
    </apex:pageBlock>


</apex:form>

</apex:page>
Best Answer chosen by John Braun
rohitsfdcrohitsfdc
Hello john,
A quick solution would be using javascipt pop up for displaying a success pop.

for example

<apex:commandButton action="{!save}" onclick="alert('Record successfully Inserted');" value="Save"/>


All Answers

rohitsfdcrohitsfdc
Hello john,
A quick solution would be using javascipt pop up for displaying a success pop.

for example

<apex:commandButton action="{!save}" onclick="alert('Record successfully Inserted');" value="Save"/>


This was selected as the best answer
John BraunJohn Braun
Perfect, that's all I need!
rohitsfdcrohitsfdc
Great. If that solves your problem, please mark this as the best solution. 
NewBie09NewBie09
The Best answer doesn't make any sense, the alert message appears once you click the save button before the controller even executes. It just displays the alert message, Even if the validation error occurs alert appears and then the error message, instead you can use CONFIRM message 
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!'));

displays the message if the record is actually inserted and without error and don't forget to add apex pageMessage to display the message.
<apex:pageMessages />

Am pretty sure many people know this yet, This would be helpful for newbie like me, who are looking for best answers :)