You need to sign in to do that
Don't have an account?
Jonathan Crow 10
Trying to test PageRedirect
I have some code in my Apex class that basically says:
public PageReference redirect(){
String somekey = [SELECT Key__c FROM Some_metadata__mdt WHERE Organization_Id__c = :runningOrg.Id].Destination_Key__c;
String URL='https://myurl.com/' + someKey + '?accId='+Account_Id__c.Id+'&sourceId='Source_Record_Id__c.Source+'&svcType='+Service_Type__c.Service+'&rsrcId='+Event_Id__c;
PageReference getFeedback=new PageReference(URL);
getFeedback.setRedirect(true);
return getFeedback;
I have written the test code as such:
@istest
static void TestPageRedirect(){
String somekey = 'UsFZNSFf';
String URL='https://myurl.com/' + surveyKey + '?accId=123456789&sourceId=123456789&svcType=My Service Type&rsrcId=My Event ID';
PageReference getFeedback=new PageReference(URL);
Test.setCurrentPage(getFeedback);
The test executes without problems but none of the code in the Apex class is shown as covered.
What am I doing wrong?
public PageReference redirect(){
String somekey = [SELECT Key__c FROM Some_metadata__mdt WHERE Organization_Id__c = :runningOrg.Id].Destination_Key__c;
String URL='https://myurl.com/' + someKey + '?accId='+Account_Id__c.Id+'&sourceId='Source_Record_Id__c.Source+'&svcType='+Service_Type__c.Service+'&rsrcId='+Event_Id__c;
PageReference getFeedback=new PageReference(URL);
getFeedback.setRedirect(true);
return getFeedback;
I have written the test code as such:
@istest
static void TestPageRedirect(){
String somekey = 'UsFZNSFf';
String URL='https://myurl.com/' + surveyKey + '?accId=123456789&sourceId=123456789&svcType=My Service Type&rsrcId=My Event ID';
PageReference getFeedback=new PageReference(URL);
Test.setCurrentPage(getFeedback);
The test executes without problems but none of the code in the Apex class is shown as covered.
What am I doing wrong?
I think you need to mention your className.methodName().
or please give you entire class so that test class can be written from scratch.
thanks
Inside @isTest , You have to create object of your apex class and call your apex method .But here you are rewriting your method logic in test method thats why its not covering your apex class
If it helps please mark as best answer
Thank you
Bhagyasri