+ Start a Discussion

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:commandButton action="{!doRedirect}" />



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.