You need to sign in to do that
Don't have an account?
SId.New dev
Code coverage problem & Error
public class Contacterrorclass { public PageReference AssignPermissionforcontact() { return null; } public list<user> u{get;set;} id contactid; public Contacterrorclass() { contactid=ApexPages.CurrentPage().getParameters().get('id'); } public PageReference AssignPermissionforcontacts() { Contact theContact= new contact(); theContact=[Select accountid,id from contact where id=:contactid]; IF(theContact.accountid!=null){ List<AccountShare> newAccountShares = new List<AccountShare>(); AccountShare thisAccountShare = new AccountShare(); //a new empty AccountShare object thisAccountShare.userorgroupid = UserInfo.getUserId(); thisAccountShare.accountid = theContact.accountid; thisAccountShare.accountaccesslevel = 'edit'; thisAccountShare.OpportunityAccessLevel = 'None'; thisAccountShare.CaseAccessLevel = 'None'; // thisAccountShare.ContactAccessLevel = 'readonly'; newAccountShares.add(thisAccountShare); insert newAccountShares; pagereference p1=new pagereference('/'+contactid); return p1; }else{ apexpages.message acctmsg=new apexpages.message(apexpages.severity.info,'Account NAME MISSING'); apexpages.addmessage(acctmsg); return null; } } }
TEST CLASS(75%) BUT ERROR_System.QueryException: List has no rows for assignment to SObject Class.contactERRORTestClass.contactERRORTESTCLASS: line 17, column 1 @istest(seealldata=true) private class contactERRORTestClass { static testMethod void contactERRORTESTCLASS() { id contactid; List<User> users = [SELECT Id FROM User WHERE IsActive = true limit 1]; test.startTest(); account acc= new account(); acc.Name='s'; insert acc; Contact theContact= new contact(); theContact=[Select accountid,id from contact where id=:contactid]; theContact.FirstName='s'; theContact.LastName='d'; theContact.accountid=acc.id; insert theContact; ApexPages.CurrentPage().getParameters().put('id',theContact.id); Contacterrorclass a= new Contacterrorclass(); //a.AssignPermissionforcontacts(); a.AssignPermissionforcontact() ; test.stopTest(); } }
HI,
The error is in the below line, as contactId is null. This will not return any row.
I think, the below line is not significant as you are inserting a newcontact. Instead of doing a query you can simlply insert account and contact record.
Not yet been solved,,,,!!!! not getting covered..when i remove query the following error