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
    Commented Sep 12, 2016 at 22:18
  • 1
    Is that even valid? Shouldn't it be ?id=a00... instead of /a00...?
    – Adrian Larson
    Commented Sep 12, 2016 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
    Commented Sep 12, 2016 at 22:26

1 Answer 1


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
    Commented Sep 12, 2016 at 22:27
  • Sounds like my hunch was right. Interesting finding.
    – Adrian Larson
    Commented Sep 12, 2016 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
    Commented Sep 12, 2016 at 23:07

You must log in to answer this question.

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