You need to sign in to do that
Don't have an account?
Mohan SFDC 25
Need help for test class
Hi All,
pls help me in code coverage
This is my controller class
This is my test class
Here i am not able to cover 43, 46 and 47 lines .
please help me
pls help me in code coverage
This is my controller class
public with sharing class Solution{ public Boolean displayPopup {get;set;} public List<Object__c> Records {get; set;} public User username {get; set;} public string userid {get; set;} public String searchTerm {get; set;} public String selecteduser {get; set;} public String uId {get; set;} public List<User> UserTemp = new List<User>(); // To load data into the table public PACV_SolutionsTab_CC(ApexPages.StandardController controller) { userid = Userinfo.getUserId(); Records = [SELECT Name,some fields,Owner.name FROM Object__c WHERE CreatedById = :userid]; system.debug(Records); } // User Auto Complete related code public String getSearchTerm() { return null; } // For auto complete functionality @RemoteAction public static List<User> searchuser(String searchTerm) { // System.debug('user Name is: '+searchTerm ); List<User> user = Database.query('SELECT Name,Id FROM User where Name like \'%' + String.escapeSingleQuotes(searchTerm) + '%\' Limit 20'); system.debug('user'+user); return user; } // Assigns permission sets to the appropriate users // This is run as part of the setup wizard and after installations. public PageReference AssignPermissionSets() { PermissionSet ps = [SELECT ID From PermissionSet WHERE Name = 'Custom_Permissionset']; list <PermissionSetAssignment> PSAssignments = new list <PermissionSetAssignment>(); List<User> users = [SELECT ID,(Select id,AssigneeId FROM PermissionSetAssignments WHERE PermissionSetID = :ps.Id) FROM User WHERE Profile.UserLicense.Name= 'Salesforce Platform' AND IsActive = true AND Id = :selecteduser]; for( User u : users ){ if(u.PermissionSetAssignments.size() == 0) PSAssignments.add( new PermissionSetAssignment(AssigneeId = u.id,PermissionSetId = ps.ID ) ); } insert PSAssignments; displayPopup = false; return null; } // To show popup and its functionality public void showPopup() { displayPopup = true; } public void closePopup() { displayPopup = false; } }
This is my test class
@isTest public class PACV_SolutionTabTest { public static testMethod void SolutionTabMethod() { Object__c o = new Object__c (Name='Test',Contact_Phone__c='0987654321',Supplier_Phone__c='1234567890'); insert o; Profile p1 = [select id from Profile where name='Standard Platform User']; User opUser = new user(alias = 'test123', email='test123@noemail.com',emailencodingkey='UTF-8', firstName='Pawan', lastname='Testing', languagelocalekey='en_US',localesidkey='en_US', profileid = p1.Id, country='United States', timezonesidkey='America/Los_Angeles', username='test01@noemail.com'); insert opUser; PermissionSet ps = [SELECT ID From PermissionSet WHERE Name = 'Custom_Permissionset']; insert new PermissionSetAssignment(AssigneeId = opUser.id, PermissionSetId = ps.Id ); PageReference myPage = Page.Solution; myPage.getParameters().put('id', o.Id); Test.setCurrentPage(myPage); ApexPages.StandardController control = new ApexPages.Standardcontroller(o); Solution pageControl = new Solution(control); pageControl.AssignPermissionSets(); pageControl.showPopup(); pageControl.closePopup(); } }
Here i am not able to cover 43, 46 and 47 lines .
please help me
Please let us know if this will help you
I am not able to cover user insersion lines. can you pls help me