You need to sign in to do that
Don't have an account?

How to get code coverage of if statement in a test class
I have a trigger that I can't get code coverage on an if statment. What am i doing wrong.
I can't get code coverage on line 33 "if (a.AccountTeamMembers == Null || a.AccountTeamMembers.isEmpty()
Here's the trigger:
I can't get code coverage on line 33 "if (a.AccountTeamMembers == Null || a.AccountTeamMembers.isEmpty()
Here's the trigger:
trigger trgAsset on Asset (after insert, after update, after delete) { if (trigger.isInsert || trigger.isUpdate){ /*If the Asset has VersaDoc and the account doesn't have a VersaDoc Project Account Team Member, it will assign the next VersaDoc Project manager from the assignment groups to the Account Team*/ Set<id> accountTeamAccountIds = new Set<id>(); // set of accountIDs that have VersaDoc in the asset for (Asset a : Trigger.new){ if (a.HasVersadoc__c == 1 || a.HasVersadocStudio__c == 1 ) { accountTeamAccountIds.add(a.AccountId); } } list<Assignment_Group_Name__c> asgnGroupNameIDs = [SELECT Id FROM Assignment_Group_Name__c WHERE Name = 'Support - VersaDoc Project Managers' limit 1]; system.debug('asgnGroupnameIDs is ' + asgnGroupNameIDs); Assignment_Groups__c[] asgnGroups = new List<Assignment_Groups__c>([SELECT Group_Name__c, User__c, Last_Assignment__c, Millisecond__c FROM Assignment_Groups__c WHERE Group_Name__c in :asgnGroupNameIds AND Active__c = 'True' AND User_Active__c = 'True' ORDER BY Last_Assignment__c, Millisecond__c] ); Integer groupCount = asgnGroups.size(); System.debug('>>>>>asgnGroups: '+asgnGroups); if (asgnGroups.isEmpty()) return; //loop through list of accounts and get the accounts w/o VersaDoc Project Manager AccountTeamMember[] NewMembers = new AccountTeamMember[]{}; //list of new team members to add AccountShare[] newShare = new AccountShare[]{}; //list of new shares to add Map<id, Account> acctsToUpdate = new Map<id, Account>([Select a.Id, (Select Id, AccountId From AccountTeamMembers WHERE TeamMemberRole = 'VersaDoc Project Manager' limit 1) From Account a Where a.Id in :accountTeamAccountIds]); Integer cnt = 0; for (Account a : acctsToUpdate.values()){ if (a.AccountTeamMembers == null || a.AccountTeamMembers.isEmpty()) { AccountTeamMember TeamMemberAd=new AccountTeamMember(); TeamMemberAd.AccountId=a.id; TeamMemberAd.UserId=asgnGroups[cnt].User__c; TeamMemberAd.TeamMemberRole = 'VersaDoc Project Manager'; NewMembers.add(TeamMemberAd); datetime now = datetime.now(); asgnGroups.get(cnt).Last_Assignment__c=now; asgnGroups.get(cnt).Millisecond__c = now.millisecondGMT(); cnt ++; if (cnt == groupCount){ cnt = 0;} } } //insert any valid members then add their share entry if they were successfully added Database.SaveResult[] lsr = Database.insert(NewMembers,false); Integer newcnt=0; for(Database.SaveResult sr:lsr){ if(!sr.isSuccess()){ Database.Error emsg = sr.getErrors()[0]; system.debug('\n\nERROR ADDING TEAM MEMBER:'+emsg); }else{ newShare.add(new AccountShare(UserOrGroupId=NewMembers[newcnt].UserId, AccountId=NewMembers[newcnt].Accountid, AccountAccessLevel='Edit',OpportunityAccessLevel='Edit')); } newcnt++; } //insert the new shares Database.SaveResult[] lsr0 =Database.insert(newShare,false); Integer newcnt0=0; for(Database.SaveResult sr0:lsr0){ if(!sr0.isSuccess()){ Database.Error emsg0=sr0.getErrors()[0]; system.debug('\n\nERROR ADDING SHARING:'+newShare[newcnt0]+'::'+emsg0); } newcnt0++; } // update assignment groups with their LastAssignmentDate update asgnGroups; } }Heres' the test class
@isTest(SeeAllData=false) private class testTrgAssetVersaDocTeamAssignment { static testMethod void myUnitTest() { // create user to run the test a User u = TestDataFactory.createTestRunAsUser('Standard User', 'Sales Assistant'); System.runAs(u) { // Switch to the runtime Test.StartTest(); // TestDataFactory.createProduct('PrinterPresence Gold Level', 'VersaDoc'); list<Account> printAccts = TestDataFactory.createTestAccounts(2, 'Printers', 'Client'); system.debug('***** printAccts is ' + printAccts); performCreateAssignmentGroups(u.Id); checkVersaDocAccountTeam(printAccts); performCreateVersaDocAssets(u.Id, printAccts); Test.StopTest(); } } public static void performCreateAssignmentGroups(id createdby){ Assignment_Group_Name__c agn = TestDataFactory.createAssignmentGroup('Support - VersaDoc Project Managers', 'Account'); list<User> u = TestDataFactory.createMulitpleUsers(2, 'Standard User-Support VersaDoc', 'Product Support Rep'); system.debug('**** user list is' + u); TestDataFactory.addUsersToAssigmentGroup(u, agn); } public static void checkVersaDocAccountTeam(list <Account> accts){ Map<id, Account> acctsToCheck = new Map<id, Account>([Select a.Id, (Select Id, AccountId From AccountTeamMembers WHERE TeamMemberRole = 'VersaDoc Project Manager' limit 1) From Account a Where a.Id in :accts]); List<Id> acct = new list<Id>(); System.debug('**** acctsToCheck is ' + acctsToCheck); for (Account a: acctsToCheck.values()){ if (a.AccountTeamMembers == null || a.AccountTeamMembers.isEmpty()) { system.debug('**** in if statement if for loop ' + acctsToCheck.values()); acct.add(a.Id); } } system.assert(acct.size()>0); } public static void performCreateVersaDocAssets(id createdby, List <Account> accts){ // add PrinterPresence Gold level Asset (Has VersaDoc) date now = date.today(); list<Account> acct = [Select Id from Account where id =: accts]; list<Asset> assts = new list<Asset>(); assts = TestDataFactory.createAssets(accts, now, 'PrinterPresence Gold Level', 'Purchased', 310.00, 7500.00); system.debug('***** assts is ' + assts); Map<id, Account> acctTeams = new map<id, Account>([Select a.Id, (Select Id, AccountId, TeamMemberRole From AccountTeamMembers WHERE TeamMemberRole = 'VersaDoc Project Manager' limit 1) From Account a Where a.Id =:accts]); system.debug('**** acctTeams after adding assets is ' + acctTeams); for (Account a : acctTeams.values()){ if (a.AccountTeamMembers != null && a.AccountTeamMembers.IsEmpty()==false) { System.assertNotEquals(a.AccountTeamMembers, Null); } } System.assert(acct.size()>0); } }
means this account not associated with any
AccountTeamMembers object
without using if condition and else how to run the below test class .please send me related code.
without using if condition and else how to run the below test class .please send me related code.