You need to sign in to do that
Don't have an account?
Ramk123
Apex Test Code Coverage Help
Dear Experts,
May I request you to help with increasing code coverage for the following highlighted missing code coverage? Appreciate your quick help.
Apex Class
Test Class
May I request you to help with increasing code coverage for the following highlighted missing code coverage? Appreciate your quick help.
Apex Class
public class ApexUtility { public static Boolean isCommunity() { if(Site.getSiteId() != null) return true; return false; } public static final String PUBLIC_USERNAME = 'Community Site Guest User'; static User publicUser; public static Boolean isLoggedInUser() { if(publicUser == null){ publicUser = [SELECT Id FROM User WHERE Name = :PUBLIC_USERNAME LIMIT 1]; } if(publicUser != null){ if(UserInfo.getUserId() != publicUser.Id) return true; } return false; } public static PageReference redirectToVipForm(String recordId) { String returnUrl = '/apex/FormWizard?id=' + recordId; if(isCommunity()){ returnUrl = '/mcr' + returnUrl; } PageReference p = new PageReference(returnUrl); p.setRedirect(true); return p; } }
Test Class
@isTest public class btn_EnableCustomerCommunityUser_ExtTest { @isTest static void testCreateCustomerUser() { Account testAccount = TestDataFactory.getPersonAccount(); insert testAccount; Test.startTest(); ApexPages.StandardController stdController = new ApexPages.StandardController(testAccount); btn_EnableCustomerCommunityUser_Ext ext = new btn_EnableCustomerCommunityUser_Ext(stdController); PageReference pr = ext.CreateCustomerCommunityUser(); Test.stopTest(); testAccount = [SELECT Id, Community_User__c FROM Account WHERE Id = :testAccount.Id LIMIT 1]; System.assertEquals(true, testAccount.Community_User__c); } }
Please use below code
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Hi
Please find the solution with 83% coverage.
Please mark it as the Best Answer so that other people would take reference from it.
Thank You.
Above is the Test Failure in isLoggedInUser while deploying. Could you please suggest?
Please share your whole code here with the test class
Thanks for the response!
The code is the same. I can also see the 83% code coverage. Throwing the test class validation error when deploying to production.