You need to sign in to do that
Don't have an account?
Long Nguyen 19
Create Data for AsyncApexJob for testing
Hi Experts,
I want to test my controller which has below query:
I want to test my controller which has below query:
List<AsyncApexJob> lstApexJob = [SELECT ApexClassId,status FROM AsyncApexJob where ApexClassId in:mapIDs.keySet()and (completedDate=yesterday or completedDate=today) ];Because there's no Job which is completed on Yesterday or Today so the List is empty and my test coverage cannot reach target percent. So I tried to create a AsyncApexJob data for testing but system said that this object is not writeable:
AsyncApexJob aaj = new AsyncApexJob(completedDate=Date.today()); insert aaj;Please show me the way to fix this issue.
(1) Open up the test to @seealldata=true and hope there is some data that your test can piggy back on. I only mention this to draw attention to the fact that its a terrible idea :)
(2) Change the query that generates the list when executing a test, so that it returns an in-memory list of previously created test records. I can't say how well this would work for your use case as it depends on what you are doing with the results.
There may be other options too, but option (2) above is the one that I typically use when I can.
could you please help me out how to change the query to generate list for testing the list what I created.