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
TemesgenTemesgen 

Test Coverage for Pagereference method with if statement

I need your assistance to complete test coverage for the following code. How do I add the Pagereference method in my test class and cover the if condition, Thank you!

```
public Pagereference newPage() {

Id classRecordTypeId = Schema.SObjectType.class__c.getRecordTypeInfosByName().get('Staff').getRecordTypeId();

String url = 'https://ourcommunity.force.com/staffportal/List?id=' + classId;

if(classType == classRecordTypeId) {

url += '&type=Staff';

}

return new PageReference(url);

}

Best Answer chosen by Temesgen
ShirishaShirisha (Salesforce Developers) 
Hi Temesgen,

Greetings!

Please refer the below thread for the sample code to cover the Pagereference in Test class.

https://developer.salesforce.com/forums/?id=906F00000005KjBIAU

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

Warm Regards,
Shirisha Pathuri

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi Temesgen,

Greetings!

Please refer the below thread for the sample code to cover the Pagereference in Test class.

https://developer.salesforce.com/forums/?id=906F00000005KjBIAU

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

Warm Regards,
Shirisha Pathuri
This was selected as the best answer
TemesgenTemesgen

Hi Shrisha!

I will check it out, thank you for your help.