You need to sign in to do that
Don't have an account?
User 444
I want help in writing test class with 100%code coverage for below apex class.
Can someone please help in writing test class for below apex class with 100% code coverage. thanks! public static List<String> getUserName(List<String> currentOwnerValues) { List<String> ownerNames = new List<String>(); set<String> uniqueIds = new set<String>(); for (String currentOwnerValue : currentOwnerValues) { String trimmedId = currentOwnerValue.trim(); If(!string.isBlank(trimmedId)){ uniqueIds.add(trimmedId); } } Map<String, User> userMap = new Map<String, User>(); if(uniqueIds.size()>0){ for( User u = [SELECT Id, Name FROM User WHERE FederationIdentifier IN :uniqueIds]; } for(String currentOwnerValue : currentOwnerValues){ String trimmedId = currentOwnerValue.trim(); User u = userMap.get(trimmedId); string ownername; if (u != null) { ownerName = String.escapeSingleQuotes(u.Name); } } catch (Exception ex) { ownerName = String.escapeSingleQuotes(trimmedId); } ownerNames.add(ownerName); } return ownerNames; }
I think this method would help you:
All Answers
I think this method would help you:
Thanks!That helped, it is 98% now.
(if (u==null)) -->else condition didnt cover up. Can you please check.
if (u != null) { ownerName = String.escapeSingleQuotes(u.Name); } }
else { ownerName = String.escapeSingleQuotes(trimmedId); }
The highlighted else code is not covered up. Could you please help.
Hello,
I think your main code is missing some lines after "for( User u = [SELECT Id, Name FROM User WHERE FederationIdentifier IN :uniqueIds];".
I'll rewrite your code in this way:
And I'm getting 100% coverage with this Test class:
If your main class is different to mine, please send it complete and I'll double check.