You need to sign in to do that
Don't have an account?
Enozzir
So I've tried a multitude of methods (insert, update, .put) but i cant seem to get the last if statement at the end to come out as true in one of my testclasses.
this if statement
*do note i'm not showing all my code just relevent sections*
For whatever reason nothing i do seems to be able to trigger that if statement and get that error message to blast off.
Unable to get my testclass to cover a an if statement that references user data
public class Risk_AnalysisExtController { public String server {get;set;} public String rootURL {get;set;} public string uId {get;set;} public String inputSer {get; set;} //line290 public List<Risk_Analysis__c> listRiskAnalysis {get; set;} //All public List<Risk_Analysis__c> custListHistory {get; set;} //when user select customer public List<Risk_Analysis__c> serListHistory {get; set;} //when user select serial public List<Risk_Analysis__c> serListAllExist {get; set;} public List<Risk_Analysis__c> serList {get; set;} public List<Risk_Analysis__c> serListAllNew {get; set;} public string paramCust {get; set;} public string paramSer {get; set;} public string paramThem {get; set;} public string inputComment {get; set;} public string paramCustText {get; set;} public string paramThemText {get; set;} public string paramBrandT {get; set;} public string paramMat {get; set;} public string actionOpt {get; set;} public date inputDate {get; set;} public string removalReason {get; set;} //public Id machId {get; set;} Map<string, Risk_Analysis__c> MapCheckSer = new Map<string, Risk_Analysis__c>(); Map<string, Risk_Analysis__c> MapCheckExist = new Map<string, Risk_Analysis__c>(); Map<string, string> MapCommentsExist = new Map<string, string>(); public string outputSer {get; set;} //line292 //public string delCust {get; set;} //public string delSer {get; set;} //private list<Risk_Analysis__c> delRisk = new list<Risk_Analysis__c>(); private Risk_Analysis__c delRisk ; public PageReference pageRef; public Map<string, string> URLParameters = ApexPages.currentPage().getParameters(); public Id currentPageId; List<riskWrapper> rList = new List<riskWrapper>(); List<Risk_Analysis__c> selectedRecords = new List<Risk_Analysis__c>(); public List<Risk_Analysis__c> delRecords = new List<Risk_Analysis__c>(); public list<riskWrapper> riskList = new List<riskWrapper>();// {get; set;} public Risk_AnalysisExtController(ApexPages.StandardController stdController) { string trustedTicket =''; //dashboard url with trusted ticket server = 'https://test.tableaureporting.test.com'; if (Functions.isProduction()) server = 'https://tableaureporting.test.com'; //currently loggedin user User u = [select name, Alias, CommunityNickname, FederationIdentifier, Domain_Credential__c, SAP_Partner_Number__c from user where Id = :UserInfo.getUserId() limit 1]; //added Domain_Credential__c string userid = ''; if(vUser(u.id).equals('Correct')) userid =u.Domain_Credential__c.toLowerCase(); if(u.SAP_Partner_Number__c!=null)uId = String.valueof('000'+u.SAP_Partner_Number__c); // system.debug('uId'+uId); // system.debug('userid = ' +userid); // system.debug('server = '+ server); //retrieve trusted ticket trustedTicket = getTicket(userid, 'Sales_Ops', server); rootURL = server+ '/trusted/'+trustedTicket; system.debug('rootURL = '+rootURL); system.debug('trustedTicket = '+ trustedTicket); //buffer serListHistory = [Select Id, Customer__c, Comments__c, Serial_Number__c, Theme__c, End_of_Life_Date__c, Action__c, Removal_Reason__c, Customer_Name__c, Brand_Name__c, Theme_Name__c, Cabinet__c from Risk_Analysis__c where Serial_Number__c=: paramSer]; serListAllExist = [Select Id, Customer__c, Comments__c, Serial_Number__c, Theme__c, End_of_Life_Date__c, Action__c, Removal_Reason__c, Customer_Name__c, Brand_Name__c, Theme_Name__c, Cabinet__c from Risk_Analysis__c where Serial_Number__c=: paramSer]; serListAllNew = [Select Id, Customer__c, Comments__c, Serial_Number__c, Theme__c, End_of_Life_Date__c, Action__c, Removal_Reason__c, Customer_Name__c, Brand_Name__c, Theme_Name__c, Cabinet__c from Risk_Analysis__c where Serial_Number__c=: paramSer]; listRiskAnalysis = [Select Id, Customer__c, Comments__c, Serial_Number__c, Theme__c, End_of_Life_Date__c, Action__c, Removal_Reason__c, Customer_Name__c, Brand_Name__c, Theme_Name__c, Cabinet__c from Risk_Analysis__c]; /*if(paramCust!= null && paramCust.isNumeric() && (paramSer == null || paramSer == '')) { String CustNumTemp; CustNumTemp = paramCust.right(7); custListHistory = [Select Id, Customer__c, Comments__c, Serial_Number__c, Theme__c, End_of_Life_Date__c, Action__c, Removal_Reason__c, Customer_Name__c, Brand_Name__c, Theme_Name__c, Cabinet__c, Delete__c from Risk_Analysis__c where Customer__c =: CustNumTemp]; } MapCommentsExist.put(paramSer, inputComment);*/ } public class riskWrapper { public Risk_Analysis__c risk{get; set;} public Boolean selected {get; set;} public RiskWrapper(Risk_Analysis__c r) { risk = r; selected = false; } } //prevent crashing sparkler server public string vUser(string uid) { User u = [select name, Alias, CommunityNickname, FederationIdentifier, Domain_Credential__c from user where Id = :uid]; string uName = u.Domain_Credential__c.toLowerCase(); if(uname == null || !u.Domain_Credential__c.contains('@') || uName.substringBefore('@').contains('.') || uName.escapeJava().contains('\\') || uname.contains('@firm2.com') || uname.contains('@firm1.com') ) { //TKT-0931762 ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Error, 'Domain Credential Error. Please log an SFDC Internal HelpDesk ticket with a screenshot. Thank you.'); ApexPages.addMessage(myMsg); return 'Domain Credential Error. Please log an SFDC Internal HelpDesk ticket with a screenshot. Thank you.'; } else return 'Correct'; }
So I've tried a multitude of methods (insert, update, .put) but i cant seem to get the last if statement at the end to come out as true in one of my testclasses.
this if statement
if(uname == null || !u.Domain_Credential__c.contains('@') || uName.substringBefore('@').contains('.') || uName.escapeJava().contains('\\') || uname.contains('@firm2.com') || uname.contains('@firm1.com') ) { //TKT-0931762 ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Error, 'Domain Credential Error. Please log an SFDC Internal HelpDesk ticket with a screenshot. Thank you.'); ApexPages.addMessage(myMsg); return 'Domain Credential Error. Please log an SFDC Internal HelpDesk ticket with a screenshot. Thank you.';
*do note i'm not showing all my code just relevent sections*
For whatever reason nothing i do seems to be able to trigger that if statement and get that error message to blast off.
In your unit test you would want to create a test user and run your tests using the 'runAs' method.
Ex:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_runas.htm
@Tom SYnder 3
thats my current test class thats giving me 83% coverage, trying to get to 90%
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_runas.htm
So in the System.runAs(u) {} brackets am i targeting my class, should i do what i did prior and insert data ? Obviously right now it doesn't do anything when i run it...
ah i can see clearly now....the rain is gone.. thank you. Do you have any good reference material for making test classes for wrapper classes?