You need to sign in to do that
Don't have an account?
venturec35
Visualforce custom Controller - retURL string
I'm building a retURL string in a test method, but am having trouble with the retURL portion.
here is the code
/* Build the Building record */ Building__c bldg = new Building__c(); bldg.name = '|Test1'; bldg.RecordTypeId = lstRcrdTyp[0].Id; Database.insert(bldg); /* Edit the Building that was just created */ PageReference pageRef = Page.BuildingEditSelect; Test.setCurrentPage(pageRef); ApexPages.currentPage().getParameters().put('id', bldg.Id); cntrBuildingSelect controller = new cntrBuildingSelect(new ApexPages.StandardController(bldg)); retURL = '/' + bldg.Id; returnURL = new PageReference('/apex/BuildingEditRCx'); returnURL.getParameters().put('id', bldg.Id); returnURL.getParameters().put('retURL', retURL); returnURL.getParameters().put('scontrolCaching', scontrolCaching); returnURL.getParameters().put('sfdc.override', '1');
I expected the retURL string to be something like:
retURL=/a0JS00000001lzS
but I'm actually getting:
retURL=%2Fa0JS000000025QNMAY
The %2F at the beginning of the Id is throwing off my test coverage.
Anyone have a possible solution for this?
Thanks.
Visualforce is correctly encoding the url query parameters. Special characters such as "/" within a query parameter are required to be encoded.
I'm not sure what you mean by "it is throwing off your test coverage". Your test should expect it to be encoded. You can use methods in EncodingUtil to decode it if you need to examine the unencoded value.
All Answers
As a follow up, it looks like the %2F is the URL Encoding for the '/', but I need to escape this character so I can build the retURL.
Anyone know how to escape a URL Character?
That is because you are adding the / char to the parameter String, but you don't need to do that, PageReference class do it by yourself.
Ignacio.
Visualforce is correctly encoding the url query parameters. Special characters such as "/" within a query parameter are required to be encoded.
I'm not sure what you mean by "it is throwing off your test coverage". Your test should expect it to be encoded. You can use methods in EncodingUtil to decode it if you need to examine the unencoded value.