Given a "save" method such as this:

public PageReference save() {

    try {
        insert current_search;
    } catch(System.DMLException e) {
        return null;

    // After successful Save, navigate to the page that shows SearchResult__c objects that are children
    // of this Search__c. 
    PageReference redirectSuccess = new PageReference('/apex/SearchResult/' + current_search.Id);
    return (redirectSuccess);

I expect to end up at URL that looks like this:


but instead I end up here:


and I see the message:

Page a0041000001QFEmAAO does not exist

How do I redirect to here?


  • Is the current code saved as with searchresult in the pagereference
    – Eric
    Sep 12 '16 at 22:18
  • 1
    Is that even valid? Shouldn't it be ?id=a00... instead of /a00...?
    – Adrian Larson
    Sep 12 '16 at 22:19
  • are you sure the save() method is getting called and there is not another place where the redirecturl is being populated?
    – Rao
    Sep 12 '16 at 22:26

The "apex" resource URL ignores path names, and only uses the last file name on the path. I tested this in my org with:


And it resolved to:


I actually didn't know about this behavior before, and I certainly wouldn't depend on it, but you definitely need to use a parameter instead of part of the file path:

PageReference redirectSuccess = new PageReference('/apex/SearchResult?id=' + current_search.Id);
  • And it has to be the fox who answers such oddities in the platform
    – Rao
    Sep 12 '16 at 22:27
  • Sounds like my hunch was right. Interesting finding.
    – Adrian Larson
    Sep 12 '16 at 23:02
  • 1
    @AdrianLarson Surprising, really. I don't think I've ever intentionally tried to break /apex/ before, but there we have it. Always something new to learn in Salesforce.
    – sfdcfox
    Sep 12 '16 at 23:07

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.