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
geosowgeosow 

Anchor is getting appended to URL parameter on redirect

I'm working with a Visualforce page that has anchors in it.  It's doing inputFile "stuff" and this requires a page refresh.  So I force the page refresh with an anchor in the pageReference like this:

 

PageReference refreshPage = new PageReference('/apex/thePage?id=' + o.Id);    	    
refreshPage.setAnchor(tabNumber);
refreshPage.setRedirect(true);
return refreshPage ;  

 

The code above works like a charm and allows me to go back to a jQuery tab on refresh of the page.  My new URL after refresh is this: https://c.cs0.visual.force.com/apex/thePage?id=006T0000008O8mVIAS#tabs-1

 

The problem I'm having is with this code:

 

PageReference newPage;
newPage = new PageReference('/apex/anotherPage?id=' + o.Id);
newPage.setRedirect(true);
return newPage;

 

With the above code I get this URL:  https://c.cs0.visual.force.com/apex/anotherPage?id=006T0000008O8mVIAS%23tabs-1

 

And I get this error:  "Id value 006T0000008O8mVIAS#tabs-1 is not valid for the Opportunity standard controller" 

 

I've tried to set the anchor to null and blank.  A debug on getAnchor shows nothing before the redirect.  For starters, I don't see why the standard controller isn't parsing out the %23 as an anchor.  And finally I don't see how the anchor is getting passed to the next page in the first case.  Any ideas?

 

I've solved this with what I would consider a hack.  I'll post it in a bit but wanted to see if anyone had some ideas.  Thanks,

 

George

 

kiranmutturukiranmutturu

may this link will helps u 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_encodingUtil.htm

 

or in the vf page u can use urlencode property....

Navatar_DbSupNavatar_DbSup

Hi,


You can also remove extra values apart from the id inside the controller by using replace method of string.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

aballardaballard

That seems like a bug to me.  Have you opened a support case?

geosowgeosow

"aballard", I agree as I think it's a bug.  I thought I'd throw it up to the community first.  But I'll create a support case now.

 

"kiran_mutturu" - I can't encode or decode anything.  A system debug on Apexpages.currentPage().getAnchor() shows null.  And I've also done this on the redirect:  newPage.setAnchor('') and  newPage.setAnchor(null) and the id still gets the anchor.

 

"Navatar_DbSup" - I did your solution as my first "hack" and that does work.  I was hoping to find something more than a hack as I hoped that I was doing something wrong.  I was parsing the id by splitting the id out with a "#" as the separator.  Like I said it works but still a hack.

 

The hack that I'm using that works and is faster than splitting or parsing is this:

 

PageReference newPage;
newPage = new PageReference('/apex/anotherPage?id=' + o.Id + '&id2=' + oId);
newPage.setRedirect(true);
return newPage;

 

By following the "id" parameter with "id2", I should be ensuring that the anchor will never be between the two parameters.  When I redirect, I get this URL:

 

https://c.cs0.visual.force.com/apex/anotherPage?id=006T0000008O8mVIAS&id2=006T0000008O8mVIAS%23tabs-1

 

So at least the standard controller gets the id correctly.  If any users ask me about the id2 parameter, I'll refer them to this thread.  I'll make a case now.

 

Thanks,

 

geosow

 

 


geosowgeosow

Thought I'd give an update.  Just heard back from SFDC support and they want to do a GoToMeeting to review my code.  Here's my reply:

 

Hi Umesh,

I’m free Monday afternoon in between 11am PT and 1pm PT.  I’ve attached a simple page and a simple class for you to reproduce.  Can you reproduce this?  Do we need to talk or can you proceed?  Thanks,

--
George Sowards
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
Salesforce.com Certified Force.com Developer
RedPoint Solutions, Inc.
office:  (303) 578-9929
profile:  linkedin.com/in/georgesowards
email:  george@redpointsolutions.com

 

Here's my page attachment (FirstPage4SFDC.page):

<apex:page standardController="Account" extensions="FirstPage4SFDC" >

<apex:form >
<apex:pageBlock >
    <apex:pageBlockButtons >
        <apex:commandButton action="{!refreshWithAnchorAndID2}" value="Click First"/>
        <apex:commandButton action="{!refreshWithAnchorOnly}" value="Click Second - DOES NOT WORK"/>
    </apex:pageBlockButtons>
    
    <apex:pageBlockSection >
        <apex:outputField value="{!Account.Name}"/>
    </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

 

And here's the extension (FirstPage4SFDC.cls):

public class FirstPage4SFDC {


    private final Account a;
    
    public FirstPage4SFDC(ApexPages.StandardController controller) 
    {
        this.a = (Account)controller.getRecord();
    }
    
    public pageReference refreshWithAnchorAndID2() 
    {
        PageReference refreshPage = new PageReference('/apex/FirstPage4SFDC?id=' + a.Id + '&id2=' + a.Id); 
        refreshPage.setAnchor('tab1');
        refreshPage.setRedirect(true);
        return refreshPage ;      
    }
        
    public pageReference refreshWithAnchorOnly() 
    {
        PageReference nextPage = new PageReference('/apex/FirstPage4SFDC?id=' + a.Id); 
        nextPage.setAnchor('tab1');
        nextPage.setRedirect(true);
        return nextPage;      
    }

}

 

Juan SpagnoliJuan Spagnoli

I'm dealing with the same issue. Did you find any solution?

 

Ohhh... one thing... I read that if you debug "refreshPage.getAnchor()", you get a NULL value, I think the problem here is that you need to reassigne the var:

 

PageReference refreshPage = new PageReference('/apex/FirstPage4SFDC?id=' + a.Id + '&id2=' + a.Id); 
refreshPage = refreshPage.setAnchor('tab1');

 

 

Thanks!

geosowgeosow

This never got resolved.  It's a bug but the support rep wanted me to buy partner premium support before he'd follow up on it.  So the solution was implemented with the hack.  I had my client create a ticket with their premium support and nobody can figure out the issue to start solving it.  I'm sorry to see you're having the same issue but I'm happy to see you're experiencing the issue; at least I know it's not just me!