1

Im am trying to get the URL of one of my PageReferences whenever i call its method to return it to me i get this result URL:[delegate:{MY RELATIVE URL}]. Anyone know if why it's returning this, Please no hacks trying to parse this string. I will note that the redirect bit is set to true in case that has anything to do with it. I am looking for an explanation, or perhaps something that I'm missing or doing wrong.

/* Cancel and Return to previous screen */
public PageReference cancel(){
   this.retUrl = retUrl.setRedirect(true);
   return this.retUrl;
}

.... Test Class

PageReference prCancel = controller.cancel();
//Test the redirects
Test.setCurrentPage( new PageReference(Url.getSalesforceBaseURL() + prCancel.getURL()) );
string currentPageURLString = Url.getSalesforceBaseURL() + ApexPages.currentPage().getURL();
string lookingForURL = Url.getSalesforceBaseUrl().toExternalForm() + '/'+controller.opportunityClone.Id+'/';

== LOG OUPUT ==

10:09:10:739 USER_DEBUG [204]|DEBUG|Url:[delegate=https://cs30.salesforce.com]/006n00000082U10AAE/

  • 4
    Might be easier to understand the issue if you could post a code snippet and example of the return value. – Ranga Oct 17 '18 at 13:30
  • 2
    Suggest you post the minimal code that demonstrates the problem; not something I have ever seen. – Keith C Oct 17 '18 at 13:51
1

Test.setCurrentPage( new PageReference(Url.getSalesforceBaseURL() + prCancel.getURL()) );

is wrong.

Test.setCurrentPage( new PageReference(prCancel.getURL()) );

getSalesforceBaseUrl returns a URL object. The delegate bit is what is being pumped up out by URL.toString().

PageReference prCancel = new ApexPages.StandardController(new Account()).cancel(); //Test the redirects
    Test.setCurrentPage( new PageReference(prCancel.getURL()) );
    string currentPageURLString = Url.getSalesforceBaseURL().toExternalForm() + ApexPages.currentPage().getURL()();
    string lookingForURL = Url.getSalesforceBaseUrl().toExternalForm() + '/xxx/';
    System.assert(false, currentPageURLString);

Returns: https://*.my.salesforce.com/home/home.jsp in my test

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.