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
Suzanne TimmerhansSuzanne Timmerhans 

This is the code provided by Salesforce for the CommunityLandingController but it yields on 33% coverage. This is killing my overall and I need to improve it. Help!

public with sharing class CommunitiesLandingController {         // Code we will invoke on page load.     public PageReference forwardToStartPage() {         String communityUrl = 'https://universaltelcom.force.com';         String customHomePage = '/apex/hello';         if (UserInfo.getUserType().equals('Guest')) {             return new PageReference(communityUrl + '/login?startURL=' + EncodingUtil.urlEncode(customHomePage, 'UTF-8'));         }else {             return new PageReference(communityUrl + customHomePage);         }       }         public CommunitiesLandingController() {}     }
Amit Chaudhary 8Amit Chaudhary 8
Please try belew test class. I hop that will help you:-
@IsTest public with sharing class CommunitiesLandingControllerTest 
{
    @IsTest(SeeAllData=true) 
	public static void testCommunitiesLandingController() 
	{
        CommunitiesLandingController controller = new CommunitiesLandingController();
        PageReference pageRef = controller.forwardToStartPage();  
    }
}
Please take more help from below post For RunAs to cover the UserInfo.getUserType().equals('Guest')​
https://developer.salesforce.com/page/Apex_Testing_with_RunAs

Please let us know if that will help you.

Thanks
Amit Chaudhary
Suzanne TimmerhansSuzanne Timmerhans
Yes – it was very helpful. I was able to bring it up to 85% - which at this point is good enough. Thank you. Suzanne Timmerhans Suzanne Timmerhans Associate Executive Director for Management Services InterAgency Council of Developmental Disabilities Agencies, Inc.