You need to sign in to do that
Don't have an account?
salesforcerrr
Test for String Query
I got a public apex class with the following query in it:
Error:
Currently i am receiving: Compile Error: Method does not exist or incorrect signature: CalendarController.findAll() at line 12 column 9
But how would i test for the string query?
Thanks
List<Case> jobs; String query='select Id, Account.Name, Time__c, End__c, Status, Type, CaseNumber from Case WHERE Time__c != null AND End__c != null'; String whereStr='';And below is my test class:
@isTest class CaseListControllerTest { static testMethod void testCaseList (){ List<Case> cases = new List<Case>(); for (Integer count = 0; count < 50; count++) { cases.add(new Case (Subject='Test', Status = 'Open')); } insert cases; Test.startTest(); CalendarController.findAll(); Test.stopTest(); Case ACC = [select phone from Account LIMIT 1]; System.assertEquals ( String.valueOf(ACC.Subject) ,'Test'); } }
Error:
Currently i am receiving: Compile Error: Method does not exist or incorrect signature: CalendarController.findAll() at line 12 column 9
But how would i test for the string query?
Thanks
In your test code, you need to create some case records that meet the criteria of your query (Time__c != null AND End__c != null). The cases your test creates now do not meet those criteria. You don't need 50 records - just enough to create a valid test. Make sure the cases you create have different values for Status and Booked_Tech__c, so that all paths through the pageLoad method are taken. You might want to create one that does not meet the criteria, so that you can assert that it was not queried.
Since there is no 'findAll()' method, there is no reason to test it. Your test code should call the 'pageLoad()' method and then assert that you have the correct data in the 'events' list.
In your controller, it looks like 'tmpJob' is used to alter the filter settings. Have you tested the controller with the alternate filter values? My concern is that when you concatenate 'query' and 'whereStr', you will get a malformed query. For example:
select Id, Account.Name, Time__c, End__c, Status, Type, CaseNumber from Case WHERE Time__c != null AND End__c != nullWHERE Account.Name = :clientId AND Booked_Tech__c = :techId
Line 34 shouldn't compile as shown. It should be:
jobs = (List<Case>) Database.query(query +whereStr);
Let me know if you have questions.
'WHERE Account.Name = :clientId'
won't do what you want. It should be:
'WHERE AccountId = :clientId'