I've updated my code to do some logic along these lines
- if no job has been created, create a job using System.enqueueJob(QC) and store it's job id.
- take a bunch of data and store it in a custom object along with the job id.
- when the job runs it will query to get the stored data matching the job id.
When I run my test methods however, the job id isn't getting set when I run System.enqueueJob() (I'm checking that using a debug statement right after setting the job Id). When I test manually, the job id is set fine. Is this just something that cannot be done in a test method? Are there other ways to test my code?
Edit: sample code
if(jobId == null){
QueueableJob context = new QueueableJob();
context.isSingletonLogic = true;
jobId = System.enqueueJob(context);
System.debug('jobID: ' + jobId);
}
TestClass
// Run as User
System.runAs( user )
{
Trigger_Config__c testCS = TestUtil.getCustomSetting(false,false,false);
insert testCS;
Account acc = TestUtil.getAccount();
}
System.runAs( userNoPermissions )
{
Test.startTest();
QueueableJob.triggerHelper(actListTest,'Account');
Test.stopTest();
List<Custom_Object__c> list = new List<Custom_Object__c>([Select Id from Custom_Object__c]);
system.assertEquals(0,list.size());
}