+ Start a Discussion
Subha Ayyappan 7Subha Ayyappan 7 

The return value of apex method to be used to check a condition in javascript in the visualforce page

Can anybody help me solve this issue?
I want to check if the user selects duplicate value of the picklist when many records are displayed to edit and show the error message and stop if duplicate is found.
I wrote a apex method for the same. Now how to take the return value to check the condition to show the error message in javascript?
My apex method is :
public Integer getcheckDuplicate() {
       // RequestsList = new List<Reclassification_Request__c>();
        
        
        for(integer i=0 ; i<RequestsList.size();i++) {
             system.debug('Entering First For Loop');
            for( integer j=(i+1) ; j<RequestsList.size() ;j++) {
                Reclassification_Request__c reclassreqI = RequestsList.get(i);
                system.debug(reclassreqI);
                Reclassification_Request__c reclassreqJ = RequestsList.get(j);
                system.debug(reclassreqJ);
                if(reclassreqI.Request__c != 'Other') {
                    if(reclassreqI.Request__c == reclassreqJ.Request__c) {
                        system.debug('Duplicate Found');
                       // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Error:Priority may not be duplicated.'));         
                        ErrorCount =  ErrorCount+1; 
                                                 
                    } 
                }            
            }
        } 
        return ErrorCount;          
      }

I want the check the value of ErrorCount and show the error message. But the value is always 0. Why? Any help please...
Best Answer chosen by Subha Ayyappan 7
sandeep@Salesforcesandeep@Salesforce
On Javascript whereve you want to check it can you please out that JS in an outpanel and refresh that panel so that you can get refreshed value. 
Make sure you have correct value in controller so Please check using debug in controller firstly. 

Thanks
Sandeep Singhal
http://www.codespokes.com/

All Answers

sandeep@Salesforcesandeep@Salesforce
On Javascript whereve you want to check it can you please out that JS in an outpanel and refresh that panel so that you can get refreshed value. 
Make sure you have correct value in controller so Please check using debug in controller firstly. 

Thanks
Sandeep Singhal
http://www.codespokes.com/
This was selected as the best answer
Subha Ayyappan 7Subha Ayyappan 7
Thank you. It helped.