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
maiyakumaiyaku 

Alert Popup in page not work

I want check country account this page is match country visited object. But it not work not show when click save

 

 

public PageReference save()
    {
    
    Account AccS = [Select id,Country__c from Account Where id =: objCus[0].AccountID__c];
    String CountryName = Accs.Country__c;
    Boolean CheckCountry = False;
    List<Country_Visited__c> lstCRV = [Select id,Name from Country_Visited__c Where Customer_Visit_ReportID__c =:    objCus[0].Customer_Visit_ReportID__c];
    
    for(Country_Visited__c CRV : lstCRV){
        if(CRV.Name == CountryName){
            CheckCountry = True;
        }
    }
    
    if(CheckCountry == True){
      
        if(objCus.size()>0)
        {  
            CountryVisited();      
            
            List<Customer_Visited__c > lstCV = [Select id from Customer_Visited__c Where AccountID__c =: objCus[0].AccountID__c];
            
            objCus[0].Nums__c = lstCV.size();        
            insert objCus;
            CusID = objCus[0].id;
            
            
        }
        insertExistingProduct(); 
        insertNewProduct();
        insertTask();
        CreateOpportunity();       
        
        return Cancel();
        }
        showmessage = 'True';
        return null;
    }
    
    public string showmessage
    {
        get;set;
    }

 Page 

 

<apex:pageBlock id="pageBlock" mode="edit">
        <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"   rerender="error" onclick="showmsg()"/>
                <apex:commandButton value="Cancel" action="{!Cancel}" rerender="error"/>                                           
        </apex:pageBlockButtons>
</apex:pageBlock>


<script> 
function showmsg(){
if('{!showMessage}'=='True'){

    alert('your message!'); 
    return false;

}
}
</script> 

 Thank so much.

Best Answer chosen by Admin (Salesforce Developers) 
Ispita_NavatarIspita_Navatar

 

Hi,

You have to do the following to correct the issue faced by you:-

  • First of all you have to check  if you are getting the value of the merge field -->  '{!showMessage}'   on VF page when you click on command button. May be merge field values are noe t retrieved on the page after th action function is called.
  • You can check that through "oncomplete" function of command button.

            function showmsg(){

                                                var flagval = '{!showMessage}';

                                                alert(flagval);

                                                if(flagval == 'True'){

                                                                alert('your message!');

                                                                return false;}

                                                }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

Pan_AKPan_AK

You are using rerender="error" But there is no apex component with this Id .

Please use Output panel

<apex:outputpanel id = ''error''>

Have your java script code under this .And I think You want the show the error

After the Processing Of the Server side ,Instead of using onclick you should

Use Oncomplete attribute .

 

 

Please tick the solution If it solve's Your Problem

maiyakumaiyaku

I've done as you suggested, but it does not work. There may be something wrong. You can preview, I look it.

 

Thank you.

Ispita_NavatarIspita_Navatar

 

Hi,

You have to do the following to correct the issue faced by you:-

  • First of all you have to check  if you are getting the value of the merge field -->  '{!showMessage}'   on VF page when you click on command button. May be merge field values are noe t retrieved on the page after th action function is called.
  • You can check that through "oncomplete" function of command button.

            function showmsg(){

                                                var flagval = '{!showMessage}';

                                                alert(flagval);

                                                if(flagval == 'True'){

                                                                alert('your message!');

                                                                return false;}

                                                }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer