You need to sign in to do that
Don't have an account?
Will Lyles
SOQL returns 0 rows when executed in a test class
I am trying to get some information about a specific user in order to run a test against my code. The first query runs fine and I can get the associated Contact Id for the user, but when I try to get the Oracle_Account_Number__c for the contact in the second query it returns 0 rows. If I copy the SOQL select statement from the debug logs and run it manually it returns the correct information, so the syntax seems to be correct.
Does anyone see any issues or know why I'm getting no results on the second query?
Does anyone see any issues or know why I'm getting no results on the second query?
@isTest public class myTestMethod { static testmethod void testupdateLineItem() { User u = [SELECT Id FROM User WHERE UserName='community.test1@example.com']; System.runAs(u) { ApexPages.StandardController sc = new ApexPages.StandardController(new Case()); m_Case_Details_Apex test = new m_Case_Details_Apex(sc); //get the contact ID based on the named user string curUserNameQry = 'SELECT ContactId FROM User where username = \'' + userinfo.getusername() + '\''; User curContactId = Database.query(curUserNameQry); //get the Oracle Account number associated with the Contact ID string oracleAcctNumQry = 'SELECT Id,Oracle_Account_Number__c from Contact where Id = \'' + curContactId.ContactId + '\''; Contact oracleAcct = Database.query(oracleAcctNumQry); string oracleAcctNum = oracleAcct.Oracle_Account_Number__c; } }
All Answers
I didn't think I needed that since it was returning the user information without it and the permissions on the contact field were set correctly.