You need to sign in to do that
Don't have an account?
Rishabh Patel 1
Test class for an Apex class that does basic lead and Event Query( I am bad at test classes)
So I have an apex class that does 6 queries , one on event and rest on leads.
I call the results of the query on a visual force page.
Everything is working perfect. The only problem is, I do not know how to create a test class for this.
Here is my apex Class that does the query
public with sharing class TestDisplayQueryList{ public List<Event> getEvents {get; set;} public List<Lead> getLeads {get; set;} public List<Lead> getlast7Leads{get; set;} public List<Lead> getlast15Leads{get; set;} public List<Lead> getlast30Leads{get; set;} public TestDisplayQueryList(){ //get all future Events getEvents = [SELECT StartDateTime,Subject,WhoId FROM Event WHERE OwnerId = :UserInfo.getUserId() AND StartDateTime = TODAY ]; //Get leads Created withing one day getLeads = [SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:1 AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5]; //Get leads created within 7 days getlast7Leads = [SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:7 AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5]; //Get leads created witing 15 days getlast15leads= [SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:15 AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5]; //Get leads Created within 30 days getlast30leads=[SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:30 AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5]; } }
I made few test classes that insert some leads and events , But was not able to go further than that.
What could be the better approach for the test class for this.
All Answers
Code coverage 100% ! Thanks a lot. Raj, you are a genius!
Thanks a lot again