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
vijayabhaskarareddyvijayabhaskarareddy 

how to use onclick in vf page

i have two apex methods Ist return tyep boolean and  2nd  return type pagereference 
 now my requirement is when i click on submit first goto boolean function and check  true or false 
 if it is true  show eler message else execute 2 nd method which perform update (DML) and return same page
srlawr uksrlawr uk
You can call an action from a button directly to do that sort of thing...

So your page might look like:
 
<apex:page controller="switchoverextension">

<apex:pageMessages ></apex:pageMessages>
<apex:form>


    <apex:commandButton action="{!doRedirect}" />

</apex:form>

</apex:page>

And your controller like:
 
public with sharing class switchoverextension {

    public boolean athing = false;
    
    public switchoverextension() {
    }

    public boolean checkthings() {
        return athing;
    }
    
    public pageReference doRedirect() {
        if(checkthings()) {
          ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'A thing was true'));
          return null;
        } else {
          // Some DML
          // Return Page Ref
          return null;
        }
    }

}

A button that checks a boolean, does DML stuff and/or redirects! Simple.