0

Hi everyone need help with my Visualforce page code I need to insert an alert message for my save button.

<apex:page lightningStyleSheets="true" controller="MycustomSettingController">
    <apex:slds /> 
       <div class="slds-page-header">
          <div class="slds-media__body">    
              <h1 class="slds-page-header__title slds-truncate slds-align-middle" >Org Information</h1>
          </div>
       </div>
    <div class="slds-scope">
        <div id="divMainContainer" style="display:flex" class="slds-col slds-size--4-of-4" >
          <div  class="slds-box slds-box_xx-small slds-text-align_center slds-m-around--xx-Large">
            <apex:form id="theForm">
               <apex:message id="showmsg"></apex:message>
                <apex:pageBlock >
                            Client ID: <br/><apex:inputField value="{!orgInfo.Client_ID__c}" required="true"/><br/>
                            Client Secret: <br/><apex:inputField value="{!orgInfo.Client_Secret__c}" required="true"/><br/>
                            Username: <br/><apex:inputField value="{!orgInfo.Username__c}" required="true"/><br/>
                            Password: <br/><apex:inputField value="{!orgInfo.Password__c}" required="true"/><br/> <br/>
                            Sandbox? <apex:inputCheckbox value="{!orgInfo.Sandbox__c}"/><br/><br/>
                           <br/>
                           <apex:commandButton styleClass="slds-button slds-button_success"   action="{!save}" value="save" rerender="showmsg"/>
                  </apex:pageBlock>
            </apex:form>
          </div>
       </div>
    </div>
</apex:page>
3
  • Possible duplicate of Call Javascript in Commandbutton – glls Aug 31 '18 at 3:31
  • the problem sir is not a custom object ist a custom setting – jan Aug 31 '18 at 4:48
  • You'd need ApexPages.addMessages(ex) to be included in the controller and might need some CSS to make it nice the message. Can you please post your controller logic as well? – highfive Aug 31 '18 at 5:14
0

<apex:message> is specifically used for a specific component, such as a warning or error. Instead use <apex:pageMessages> which displays all messages that were generated for all components on the current page.

You'd need ApexPages.addMessages(ex) to be included in the controller Save method as suggested by high-five suggested in comments.

You are using lightningStyleSheets="true", so your VF page will be automatically rendered in Lightning UI and apex:pageMessages is also supported and no specific CSS is required.

<apex:page lightningStyleSheets="true" controller="MycustomSettingController">
    <apex:slds /> 
    <div class="slds-page-header">
        <div class="slds-media__body">    
            <h1 class="slds-page-header__title slds-truncate slds-align-middle" >Org Information</h1>
        </div>
    </div>
    <div class="slds-scope">
        <div id="divMainContainer" style="display:flex" class="slds-col slds-size--4-of-4" >
            <div  class="slds-box slds-box_xx-small slds-text-align_center slds-m-around--xx-Large">
                <apex:form id="theForm">
                    <apex:pageMessages id="showmsg"></apex:pageMessages>
                    <apex:pageBlock >
                        <!--
                        ....
                        -->
                        <apex:commandButton styleClass="slds-button slds-button_success" action="{!save}" value="save" rerender="showmsg"/>
                    </apex:pageBlock>
                </apex:form>
            </div>
        </div>
    </div>
</apex:page>

Controller

public class MycustomSettingController {
    public pageReference save(){
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.CONFIRM,'CONFIRM: Account Created.');
        ApexPages.addMessage(myMsg);
        return null;
    }
}

If you want to show the message as Lightning Toast Message you have to create the custom Toast Message using SLDS. Please go through this dev forum link can we show toast messages on visual force pages using java-script ? for details.

4
  • the code is code but i after i save the data are still there? what should i do? – jan Aug 31 '18 at 6:38
  • Please explain a little bit more. – Saroj Bera Aug 31 '18 at 6:44
  • the problem now is the after I click the save button the alert message pop up but still the data that ive input in the text field are still there i need now the refresh button to refresh the page – jan Aug 31 '18 at 6:49
  • Please check this link salesforce.stackexchange.com/questions/63251/… – Saroj Bera Aug 31 '18 at 7:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.