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
VSK98VSK98 

System.NoAccessException: Invalid Page Redirection: getting error in test class

Hello Team,

I hv created a login flow, that was embedded into VF Page and it is working as expected. While writing the test class getting the error to cover the SessionManagement Methods.

ERROR:
System.NoAccessException: Invalid Page Redirection: The page you attempted to access has been blocked due to a redirection to an outside website or an improperly coded link or button. Please contact your salesforce.com Administrator for assistance.

Test Class:
@isTest
public class popupcontroller_Test {

 
    static testmethod void loginflow(){
    List<User> lstusers = new list<User>();
    lstusers = Utility.createUser('Business Admin', 1, 'ab'); 
    system.debug('lstusers######'+lstusers);
        string retURL;
        Test.starttest();
         PageReference pageRef = Page.login;
         Test.setCurrentPage(pageRef); 
        popupcontroller popupControllerClass = new popupcontroller();
        popupControllerClass.openPopup();
        popupControllerClass.Cancel(); 
        popupControllerClass.updateRecord();
        
        lstusers[0].Skip_Login_Flow__c = true;
        update lstusers;
        pageref.getParameters().put('retURL', 'home/home.jsp');
        Auth.SessionManagement.finishLoginFlow(retURL);
        popupControllerClass.openPopup();
        popupControllerClass.CurrentRecord();
        Test.stoptest();
    }
}

Base Class:
 
String retURL = apexpages.currentpage().getparameters().get('retURL');
 
            return Auth.SessionManagement.finishLoginFlow(retURL);

Thanks.
VSK98​​​​​​​​​​​​​​
 
ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

Seems like you are trying to use the url which might be causing the issue here.So,I would suggest you to double check if the url that you are using is valid.

Please refer the below thread for the more information:
https://developer.salesforce.com/forums/?id=906F00000009Bc3IAE

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Abhishek BansalAbhishek Bansal
Can you try replacing this line pageref.getParameters().put('retURL', 'home/home.jsp'); -> pageref.getParameters().put('retURL', '/home/home.jsp');

Let me know if this works for you.
VSK98VSK98
Hi Abhishek,

Thanks for your response......No luck with your changes in code, getting the same error.

Regards,
VSK98