You need to sign in to do that
Don't have an account?
Brenden Burkinshaw 10
Apex Controller and Visualforce Page Error
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
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
Define your ObjId variable as String Type.
Exp:
public String objId {get; set;}
Thanks.