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
Anjali RAnjali R 

apex:actionFunction is not getting called always.

I have written page redirection logic in controller  in the  action function. Sometimes it is redirecting to the expected page and sometimes it is staying in the same page after submit button click.

Please help !! 
Grazitti TeamGrazitti Team
Hi Anjali,

When you click on a button an action method is called from controller and in the last of that method redirect to your desired page. For example following is the command button.
<apex:commandButton action="{!Click}" value="Click Me" reRender="none"/>
When you click on this "Click" method from controller is executed.
public pageReference click(){

    //your code
    PageReference pref = Page.YOUR_PAGE_NAME;
    return pref;


Please mark it as best if this helps you.

Grazitti Team
Anjali RAnjali R
Thanks  Grazitti Team.
I have done the redirection in the same manner which you mentioned.

Below is my sample code:

setImageContentsString method should only be called after performing some operations inside setValuesToVariable  method. Because i need to get the converted result of canvas.toDataURL('image/png') before executing setImageContentsString.It gets executed properly many times(redirection also works fine).Problem is sometimes it stays back in the same page. In logs also I am not able to find any error.

Please help.

 apex page
 <apex:CommandButton value="Submit"   id="cmdNext" onclick="return setValuesToVariable('{!$Component.hdnobj}')" /> 
                    <apex:actionFunction name="myimage" action="{!setImageContentsString}" >

function setValuesToVariable(hiddenCanvas){
            var confirmSuccess = confirm("Please double check your work.Changes to sketch cannot be made after submitting.Do you want to proceed? ");
             html2canvas($('#rightPaneSketch'), {  
                    onrendered: function(canvas) {
                        var data = canvas.toDataURL('image/png');
                        document.getElementById(hiddenCanvas).value = data;
                        console.log("data >>** "+data);
                        console.log("data after >>** "+data);
             return true;
                return false;
public PageReference setImageContentsString()
     //attachment insert code 
     // redirection code
      PageReference p=Page.testform;
        return p;