You need to sign in to do that
Don't have an account?
SOQL Not Returning Requested Fields
Hi All,
I'm currently writing a test batch class and I'm scratching my head trying to figure out why my SOQL query is not returning the requested fields:
Here's the condensed version of the class:
@isTest static void testTaskUpdateActivityInfoBatchTest() { DateTime olderTime = system.now().addMinutes(-5); DateTime newestTime = system.now().addMinutes(-3); //Pull a random active sales guy User testUser = [SELECT Id FROM User WHERE ProfileId ='00e30000001Ghun' AND IsActive = true LIMIT 1]; List<Task> tasks = new List<Task>(); //Create test Leads Lead[] testLeads = new Lead[]{}; for(Integer i = 0; i < 10; i++) { testLeads.add(new Lead(LastName = 'kktest-'+i, Company='test', Date_Requested_Sales_Follow_Up__c = system.now())); } insert testLeads; //Create 60 tasks associated to these leads for(Integer i = 0; i < 30; i++) { Integer j = math.mod(i, 10); tasks.add(new Task(OwnerId = testuser.Id, Subject = 'Apex Test '+i, ActivityDate = system.today(), Status = 'Completed', WhoId = testLeads[j].id, In_Queue_for_Processing__c = true, Date_Time_Processed__c = newestTime, Prospecting_call_affirmative__c = true, Prospecting_call_connected__c = true, Email_Connection__c = true)); tasks.add(new Task(OwnerId = testuser.Id, Subject = 'Apex Test '+i, ActivityDate = system.today(), Status = 'Completed', WhoId = testLeads[j].id, In_Queue_for_Processing__c = true, Date_Time_Processed__c = olderTime, Prospecting_call_affirmative__c = true, Prospecting_call_connected__c = true, Email_Connection__c = true)); } system.assertEquals(60, tasks.size()); Test.startTest(); Database.executeBatch(new TaskUpdateActivityInfoBatch()); Test.stopTest(); //Asserts List<Lead> leadsToCheck = [SELECT Id, First_Activity_Id__c, First_Activity_Date_Time__c, First_Connection_Date_Time__c, Last_Connection_Date_Time__c, Second_to_Last_Activity_Date_Time__c, Last_Activity_Date_Time__c FROM Lead WHERE Id =:testLeads]; system.debug('leadsToCheck: ' + leadsToCheck); for(Lead lead : leadsToCheck) { //Cannot assert Id with this set up system.assertEquals(olderTime, lead.First_Activity_Date_Time__c); system.assertEquals(olderTime, lead.First_Connection_Date_Time__c); system.assertEquals(newestTime, lead.Last_Connection_Date_Time__c); system.assertEquals(olderTime, lead.Second_to_Last_Activity_Date_Time__c); system.assertEquals(newestTime, lead.Last_Activity_Date_Time__c); } }
The last query
List<Lead> leadsToCheck = [SELECT Id, First_Activity_Id__c, First_Activity_Date_Time__c, First_Connection_Date_Time__c, Last_Connection_Date_Time__c, Second_to_Last_Activity_Date_Time__c, Last_Activity_Date_Time__c FROM Lead WHERE Id =:testLeads];
When I observe it in the debug logs is only returning the Ids:
16:22:42:080 USER_DEBUG [74]|DEBUG|leadsToCheck: (Lead:{Id=00Q8A000001HaZ6UAK}, Lead:{Id=00Q8A000001HaZ7UAK}, Lead:{Id=00Q8A000001HaZ8UAK}, Lead:{Id=00Q8A000001HaZ9UAK}, Lead:{Id=00Q8A000001HaZAUA0}, Lead:{Id=00Q8A000001HaZBUA0}, Lead:{Id=00Q8A000001HaZCUA0}, Lead:{Id=00Q8A000001HaZDUA0}, Lead:{Id=00Q8A000001HaZEUA0}, Lead:{Id=00Q8A000001HaZFUA0})
Why are the other fields not returning and how do I fix it?
Thanks,
Kelly
When did they change the behavior of system.debug to not show null values? It makes troubleshooting irritating during testing/debugging. Is there an alternative method to quickly pull back all of it?
In regards to insert task - must've deleted it when I pasted into the window above. Regardless though - there may be something else going and it's not properly spitting out an error like I would expect. Doing some prodding around a custom Apex_Errors__c object I have and it's returning someting like this:
16:48:46:770 USER_DEBUG [76]|DEBUG|apex errors: (Apex_Error__c:{Id=a2i8A00000003GMQAY, Apex_Class__c=TaskUpdateActivityInfoBatch, Error_Record__c=00T8A000002zf4AUAQ, Error_Details__c=Attempt to de-reference a null object}, ......
I'm trying to see if I can figure out exactly what it's considering null because I can extract the code and run it in execute anonymous and it does what it's supposed to.
But it's there - here's the full beast atm if you want to verify my insert statement is in there.
Did you check Field Level Security for those fields ?
Found it - the error was coming out of the supporting apex class, not the batch class itself, which is why I wasn't seeing an error in the debug logs.
This was causing an error because the WhoId is null.
I just wrapped it with an if statement to check if it's null 1st and it looks like it's good:
Thanks for the helpful line of questioning folks. Good to know system debug will no longer show me null fields. I'll spend less time troubleshooting that next time.