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
uHaveOptionsuHaveOptions 

Salesforce Button Redirect

My redirect button is not working.  Not sure why or where I'm missing the code.  Can anyone help?  The goal is when it updates I want it to go to a webpage.

This is my button

<apex:commandButton value="Update" action="{!save}" styleClass="btn pull-right" onclick="$j('#pleaseWaitDialog').modal('show')" oncomplete="$j('#pleaseWaitDialog').modal('hide')"/>
<div class="modal fade" id="pleaseWaitDialog" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <h3>Processing...</h3><br/>
                        <div class="progress">
                            <div class="progress-bar progress-bar-striped active" role="progressbar"
                            aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:100%">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
 

 


This is my APEX
public void save() {
        try {
            if(accountUpdate.Account__c == null) {
                accountUpdate.Account__c = accountId;
            }
            upsert accountUpdate;
            PageReference reRend = new PageReference('GOOGLE.COM');
        reRend.setRedirect(true);
        } catch(Exception e) {
            System.debug('------------- ERROR: ' + e.getStackTraceString());
            System.debug('------------- ERROR: ' + e.getMessage());
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'There was a problem while saving the account information.'));
            return;
        }
    }


Thanks
Best Answer chosen by uHaveOptions
Kai Herng LauKai Herng Lau
ok, but the error message mean that you method is set to void can you double check, if you have changed the method return type to 'PageReference'
 

All Answers

Kai Herng LauKai Herng Lau
Hi Jon,

Can you try to update your Save() method to return reRend?
public PageReference save() {
        try {
            if(accountUpdate.Account__c == null) {
                accountUpdate.Account__c = accountId;
            }
            upsert accountUpdate;
            PageReference reRend = new PageReference('GOOGLE.COM');
            reRend.setRedirect(true);
            return reRend;
        } catch(Exception e) {
            System.debug('------------- ERROR: ' + e.getStackTraceString());
            System.debug('------------- ERROR: ' + e.getMessage());
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'There was a problem while saving the account information.'));
            return;
        }
    }
Let me know if you still have problem
 
uHaveOptionsuHaveOptions
I actually did that and I got an error - Error: Compile Error: Void method must not return a value at line 28 column 13

I did a code where it will say recoed updated but would like to be able to send to a web page.
Kai Herng LauKai Herng Lau
Hi Jon,

Do you mind to share the complete code? Cause the error message you mention is pointed to line 28, I cannot see what is in that line.

 
uHaveOptionsuHaveOptions

The line 28 is - return reRend; line.
 

Kai Herng LauKai Herng Lau
ok, but the error message mean that you method is set to void can you double check, if you have changed the method return type to 'PageReference'
 
This was selected as the best answer
uHaveOptionsuHaveOptions
It was still goiving me errors but I changed the Void to Page REfence and changed the ApexPAges.Massage to a redirect as well.  We go to go.  Thank you.