I am attempting to redirect the user back to a specific tab upon Save. I thought I had got it with this code, but I am unable to use a Return in the public void Save()

public void save()

        System.debug('********************************' + names);

        message = null ;       
        Boolean first = true;
        for ( SelectOption so : selectedSubs ) {
            if (first) {
                message = message ;

            message = message + ', ' + so.getValue() ;

            first = false;


        message=message.removeStart('null, ');

        System.debug('********************************' + message);

        insert contract;
        contract=new Contract_Overview__c  ();
        System.debug('********************************' + contract);

      PageReference pr = new PageReference('/a23/o');
      return pr;


The tab I am attempting to get back to is the /a23/o ;

Can anybody give some input on this ?

Thank you very much.

1 Answer 1


Your save method is set for as void. You will want to change it to use a PageReference return type.

public PageReference save()
      //Do Stuff 

      PageReference pr = new PageReference('/a23/o');
      return pr;
  • Thanks Brad ! I figured it was something simple - just thought the void save would still allow me to get away with it.
    – Zoom_v
    Apr 29, 2013 at 16:24
  • 2
    It's better to dynamically retrieve the prefix of the sobject (in case of a managed package or the prefix changing).. See Andy's simple example in the link below, appending '/o' to the end of the string . techman97.wordpress.com/2012/04/17/getting-prefix-of-sobject Apr 29, 2013 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.