• Brenden Burkinshaw 10
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi All,

I have created the below visual force page and apex controller, but get the following error message when redirected to this page. Can anybody see an error with the code, this visual force page URL is embedded in a custom button on a custom object within our org.

Invalid id: <a href="https://cs57.salesforce.com/a3Z0k0000004QjG" target="_blank">Process Payment</a>
Error is in expression '{!validateAndRedirect}' in component <apex:page> in page svmxredirectpage: Class.SVMXGenericRedirectController.validateAndRedirect: line 8, column 1
 
An unexpected error has occurred. Your development organization has been notified.

SVMXRedirectPage
 
<apex:page controller="SVMXGenericRedirectController" action="{!validateAndRedirect}">
  <apex:pageMessages ></apex:pageMessages>
</apex:page>
 
SVMXGenericRedirectController
public class SVMXGenericRedirectController {
 
 
    public Id objId {get; set;}
   
    public PageReference validateAndRedirect(){
       
        if (ApexPages.currentPage().getParameters().get('objId') != null && ApexPages.currentPage().getParameters().get('objId') != '') {
            objId = ApexPages.currentPage().getParameters().get('objId');
           
            PageReference retURL = new PageReference('/' + objId);
            retURL.setRedirect(true);
            return retURL;
        } else {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.WARNING, Label.SVMXMissingId));
        }
       
        return null;
    }
   
}
 
SVMXGenericRedirectControllerTest
@isTest
public class SVMXGenericRedirectControllerTest {
 
 
    public testmethod static void SVMXGenericRedirectControllerTest() {
        
        Test.StartTest();
       
        PageReference pageRef = Page.SVMXRedirectPage;
        pageRef.getParameters().put('objId', 'a3Z0k0000004Lwi');
        Test.setCurrentPage(pageRef);
       
        SVMXGenericRedirectController svmxController = new SVMXGenericRedirectController();
        svmxController.validateAndRedirect();
       
        Test.StopTest(); 
         
    } 
   
    public testmethod static void SVMXGenericRedirectControllerWithoutParamsTest() {
        
        Test.StartTest();
       
        PageReference pageRef = Page.SVMXRedirectPage;
        Test.setCurrentPage(pageRef);
       
        SVMXGenericRedirectController svmxController = new SVMXGenericRedirectController();
        svmxController.validateAndRedirect();
       
        Test.StopTest(); 
         
    } 
   
}

Thanks,
Brenden