Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would you add # in the URL via passing from PageReference? I have tried few different way but that does not work.

public PageReference clickOnName() 
{ 
    PageReference newPage = Page.NewEmployee; 
    newPage.getParameters().put('empId', empId + '#menu');  
    return newPage.setRedirect(true); 
} 

The above URL will be something:

http://xxxxx.visual.force.com/apex/NewEmployee?id=ABC%23menu

Instead I want:

http://xxxxx.visual.force.com/apex/NewEmployee?id=ABC#menu
share|improve this question
    
Why do you think setting a parameter is likely to do something other than setting the parameter? – immibis 4 hours ago
up vote 6 down vote accepted

You need to use Map#setAnchor instead:

PageReference newPage = Page.NewEmployee; 
newPage.getParameters().put('empId', empId);
newPage.setAnchor('menu');  
return newPage.setRedirect(true); 
share|improve this answer
    
1+ I did not aware of the setAnchor thanks for that... able to add anchor to the URL but my page is white blank after it redirects any thoughts? – Nick Kahn 11 hours ago
    
@NickKahn Off the top of my head, not sure. Did you check your console for any errors? Developer Console debug logs? Are you using an iframe to display your page? – sfdcfox 11 hours ago
    
I don't see any errors in the console logs and the weird thing is that if I hit ENTER on the URL then the page loads property with anchor tag selected. – Nick Kahn 11 hours ago
    
another test I did was not adding setAnchor and after it redirecting I see the page but when add setAnchor after it redirects I get white blank page. – Nick Kahn 11 hours ago
    
@NickKahn Hmm. It works for me when I tested it using a simple mockup. I'm not sure what to tell you. – sfdcfox 10 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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