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
Agustín MedinaAgustín Medina 

Close a modal automatically

I'm developing a visualforce which after query an opportunity displays a modal and the modal has a button to close itself but I want to close it automatically, does anyone knows how to do it?

My apex code is 
public without sharing class RegistroCitas {
	
    Public String correo{get; set;}
    Public List<Account> cuenta = new List<Account>();
    Public List<Oportunidad_Univer__c> oportunidad = new List<Oportunidad_Univer__c>();
	Public PageReference pageRef = ApexPages.currentPage();
    public boolean displaySuccesPopup {get; set;}
    public boolean displayFailedPopup {get; set;}
    public boolean boleano {get; set;}
    
    public RegistroCitas(){
        displaySuccesPopup = false;
        displayFailedPopup = false;
    }
    
    public PageReference registrarCita(){
        cuenta = [SELECT Acc_Asistio__c FROM Account WHERE PersonEmail =: correo];
        if(cuenta.isEmpty()){
            displayFailedPopup = true;
            correo = '';
            return null;
        }else{
            //Si hay cuenta
            oportunidad = [SELECT Id, Name, Opp_Atendio_cita__c ,CreatedDate FROM Oportunidad_Univer__c WHERE Opp_Cuenta__c =: cuenta[0].Id ORDER BY CreatedDate DESC LIMIT 1];
            if(oportunidad.size() < 1){
                displayFailedPopup = true;
                correo = '';
                return null;
            }else{
             	oportunidad[0].Opp_Atendio_cita__c = True;
            	cuenta[0].Acc_Asistio__c = True;
            	update oportunidad;
            	update cuenta;	
                displaySuccesPopup = true;
                correo = '';
            	return pageRef; 
            }
        }
    }
    
    public void closePopup(){
        displaySuccesPopup = false;
        displayFailedPopup = false;
    }
}

and te visualforce is 
<apex:page>
	<apex:form >
		<div class="container">
            <div class="cabecera centrado">
                <div class="imagen">
                    <apex:image url="{!URLFOR($Resource.images, 'images/logoUniver-Blanco.png')}" width="500" height="100" />
                </div>
            </div>
            <div class="margen centrado">
				<h1 class="grande">Registro para Citas Agendadas</h1>
                <p><u>Favor de ingresar su correo electrónico</u></p>
                <apex:inputText value="{!correo}"/><br/>
                <br/>
            	<apex:commandButton value="Enviar" action="{!registrarCita}"/>
            </div>  
		</div>
	</apex:form>
    
    <apex:form >
        <apex:outputPanel id="tstpopup">
        <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displaySuccesPopUp}"/>
            <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displaySuccesPopUp}">
                ¡Tu cita ha quedado registrada! :)<br/><br/><br/>
                <apex:commandButton value="Cerrar" action="{!closePopup}" rerender="tstpopup"/>
            </apex:outputPanel>
            <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayFailedPopUp}"/>
            <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayFailedPopUp}">
                No se encontró su cita, favor de buscar asistencia de parte de nuestro equipo en recepción.<br/><br/><br/>
                <apex:commandButton value="Cerrar" action="{!closePopup}" rerender="tstpopup"/>
            </apex:outputPanel>
        </apex:outputPanel>
 
    </apex:form>
</apex:page>

 
Mohammad Asim AliMohammad Asim Ali
By automatically, you mean you want to close it after a time lapse. On click of your command button, when your modal pops up, call a javascript function, which in turn will call an action function after a javascript timeout. In the action function, call an apex method and make your boolean value as false used to render the popup and then rerender the modal. This will hide your modal popup.
Agustín MedinaAgustín Medina
I rewrite the code but it still doesn't work.
<script>
    	function setTime(){
            setTimeout(closePopup, 5000);
        }
    </script>
	<apex:form >
		<div class="container">
            <div class="cabecera centrado">
                <div class="imagen">
                    <apex:image url="{!URLFOR($Resource.images, 'images/logoUniver-Blanco.png')}" width="500" height="100" />
                </div>
            </div>
            <div class="margen centrado">
				<h1 class="grande">Registro para Citas Agendadas</h1>
                <p><u>Favor de ingresar su correo electrónico</u></p>
                <apex:inputText value="{!correo}"/><br/>
                <br/>
            	<apex:commandButton value="Enviar" action="{!registrarCita}" onclick="setTime()"/>
            </div>  
		</div>
	</apex:form>
    
    <apex:form >
        <apex:outputPanel id="tstpopup">
        <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displaySuccesPopUp}"/>
            <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displaySuccesPopUp}">
                Tu cita ha quedado registrada.<br/><br/><br/>
                <apex:commandButton value="Cerrar" action="{!closePopup}" rerender="tstpopup"/>
            </apex:outputPanel>
            <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayFailedPopUp}"/>
            <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayFailedPopUp}">
                Hay un error con su cita, favor de buscar asistencia de parte de nuestro equipo en recepción.<br/><br/><br/>
                <apex:commandButton value="Cerrar" action="{!closePopup}" rerender="tstpopup"/>
            </apex:outputPanel>
        </apex:outputPanel>
 		<apex:actionFunction action="{!closePopup}" name="closePopup" rerender="tstpopup"/>
    </apex:form>