1

I have a save method in an apex controller which returns a page reference(This method is called on clicking the save button from the visualforce page). I have 2 scenarios

  1. On click of save button click, this method is called and the page reference is returned.
  2. I want an alert to be displayed in the new page once the save method has been called.

One of these conditions occur according to the value of a boolean variable. I am not sure how to go about this. Any help would be appreciated. Thanks in advance

1
  • set some value in URL and based on that display the message. Commented Jan 28, 2016 at 4:47

1 Answer 1

1

In the save method in the controller - you are returning a pagereference. I am not aware if you are hardcoding the pagereference or dynamically generating it, irrelevant of that - pass the Boolean variable as a parameter to the next page. Add the following line before returning the pageReferenceVariable at the end of the save method.

pageReferenceVariable.getParameters().put('BooleanVariableName', 'BooleanVariableValue');

Then, in the controller of the second page, in which you want to display the alert, get the value of the Boolean variable. Use the code as below:

Boolean passedBooleanVariableValue = system.CurrentPageReference.GetParameters().get('BooleanVariableName');

Now you have the boolean variable value in the current page. Based on this value you can decide to show the alert on not. Use a javascript function on the page, that will fire the alert if the passed Boolean variable is true.

<script>
function showAlert(passedBooleanVariableValue ) {
      if(passedBooleanVariableValue ) {
        alert('Hi I am the alert you have been waiting for');
      }
}
</script>

Hope this helps. Thanks

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .