@isTest
public class BatchSendEmailAlerts8Test{
public static testMethod void method1(){
List<Apply_Job__c> applyLst = new List<Apply_Job__c>();
Apply_Job__c apply = new Apply_Job__c();
apply.Status__c = 'Pending Approval';
apply.Qualification__c='B.pham';
apply.Next_Alert_Schduled_Date__c = system.today();
insert apply;
applyLst.add(apply);
Apply_Job__c apply1 = new Apply_Job__c();
apply1.Status__c = 'Pending Approval';
apply1.Qualification__c='B.pham';
apply1.Next_Alert_Schduled_Date__c= system.today();
insert apply1;
applyLst.add(apply1);
Apply_Job__c apply2 = new Apply_Job__c();
apply2.Status__c = 'Pending Approval';
apply2.Qualification__c='B.pham';
apply2.Next_Alert_Schduled_Date__c= system.today();
insert apply2;
applyLst.add(apply2);
try {
for(Apply_Job__c a: applyLst) {
// Create an approval for the account and submit
Approval.ProcessSubmitRequest AccountRequest = new Approval.ProcessSubmitRequest();
AccountRequest.setObjectId(a.ID);
Approval.ProcessResult AccountRequestResult = Approval.Process(AccountRequest);
ProcessInstanceWorkitem pworkItem = new ProcessInstanceWorkitem();
pworkItem.ActorId = userinfo.getuserId();
pworkItem.OriginalActorId = userinfo.getuserId();
pworkItem.ProcessInstanceId = AccountRequestResult.ID;
insert pworkItem;
System.assert(AccountRequestResult.isSuccess());
} // loop thru accounts submitting them for approval
} catch (DMLException e) {
system.debug('>>>> NO APPROVAL PROCESS FOR ACCOUNTS!');
}
BatchSendEmailAlerts8 batch = new BatchSendEmailAlerts8();
Test.StartTest();
Database.executeBatch(batch);
Test.StopTest();
}
}
++++++++++++++++++++++++++++++
ProcessInstance proc = new ProcessInstance();
proc.LastActorId = userinfo.getuserid();
proc.TargetObjectId = apply.id;//applyjob record id
insert proc;
ProcessInstanceWorkitem pworkItem = new ProcessInstanceWorkitem();
pworkItem.ActorId = userinfo.getuserId();
pworkItem.OriginalActorId = userinfo.getuserId();
pworkItem.ProcessInstanceId = proc.id;
insert pworkItem;
@isTest
public class BatchSendEmailAlerts8Test{
public static testMethod void method1(){
List<Apply_Job__c> applyLst = new List<Apply_Job__c>();
set<Id> applyIds = new set<Id>();
Apply_Job__c apply = new Apply_Job__c();
apply.Status__c = 'Pending Approval';
apply.Qualification__c='B.pham';
apply.Next_Alert_Schduled_Date__c = system.today();
insert apply;
applyLst.add(apply);
Apply_Job__c apply1 = new Apply_Job__c();
apply1.Status__c = 'Pending Approval';
apply1.Qualification__c='B.pham';
apply1.Next_Alert_Schduled_Date__c= system.today();
insert apply1;
applyLst.add(apply1);
Apply_Job__c apply2 = new Apply_Job__c();
apply2.Status__c = 'Pending Approval';
apply2.Qualification__c='B.pham';
apply2.Next_Alert_Schduled_Date__c= system.today();
insert apply2;
applyLst.add(apply2);
for(Apply_Job__c apps:applyLst)
{
applyIds.add(apps.id);
}
ProcessInstance proc = new ProcessInstance();
proc.LastActorId = userinfo.getuserid();
proc.TargetObjectId = apply.id;//applyjob record id
insert proc;
system.debug('processInstance record inerted----'+proc.id);
ProcessInstanceWorkitem pworkItem = new ProcessInstanceWorkitem();
pworkItem.ActorId = userinfo.getuserId();
pworkItem.OriginalActorId = userinfo.getuserId();
pworkItem.ProcessInstanceId = proc.id;
insert pworkItem;
system.debug('processInstancework item record inerted----'+pworkItem.id);
List<ProcessInstanceWorkitem> pworkLst = [select id,ActorId,ProcessInstanceId,actor.email,ProcessInstance.TargetObjectId from ProcessInstanceWorkitem where ProcessInstance.TargetObjectId in: applyIds];
system.debug('pworkLst is ---------'+pworkLst.size());
BatchSendEmailAlerts8 batch = new BatchSendEmailAlerts8();
Test.StartTest();
Database.EexecuteBatch(batch);
Test.StopTest();
}
}
http://salesforce.stackexchange.com/questions/17981/processinstanceworkitems-not-created-when-running-an-approval-process-unit-test
public class BatchSendEmailAlerts8Test{
public static testMethod void method1(){
List<Apply_Job__c> applyLst = new List<Apply_Job__c>();
Apply_Job__c apply = new Apply_Job__c();
apply.Status__c = 'Pending Approval';
apply.Qualification__c='B.pham';
apply.Next_Alert_Schduled_Date__c = system.today();
insert apply;
applyLst.add(apply);
Apply_Job__c apply1 = new Apply_Job__c();
apply1.Status__c = 'Pending Approval';
apply1.Qualification__c='B.pham';
apply1.Next_Alert_Schduled_Date__c= system.today();
insert apply1;
applyLst.add(apply1);
Apply_Job__c apply2 = new Apply_Job__c();
apply2.Status__c = 'Pending Approval';
apply2.Qualification__c='B.pham';
apply2.Next_Alert_Schduled_Date__c= system.today();
insert apply2;
applyLst.add(apply2);
try {
for(Apply_Job__c a: applyLst) {
// Create an approval for the account and submit
Approval.ProcessSubmitRequest AccountRequest = new Approval.ProcessSubmitRequest();
AccountRequest.setObjectId(a.ID);
Approval.ProcessResult AccountRequestResult = Approval.Process(AccountRequest);
ProcessInstanceWorkitem pworkItem = new ProcessInstanceWorkitem();
pworkItem.ActorId = userinfo.getuserId();
pworkItem.OriginalActorId = userinfo.getuserId();
pworkItem.ProcessInstanceId = AccountRequestResult.ID;
insert pworkItem;
System.assert(AccountRequestResult.isSuccess());
} // loop thru accounts submitting them for approval
} catch (DMLException e) {
system.debug('>>>> NO APPROVAL PROCESS FOR ACCOUNTS!');
}
BatchSendEmailAlerts8 batch = new BatchSendEmailAlerts8();
Test.StartTest();
Database.executeBatch(batch);
Test.StopTest();
}
}
++++++++++++++++++++++++++++++
ProcessInstance proc = new ProcessInstance();
proc.LastActorId = userinfo.getuserid();
proc.TargetObjectId = apply.id;//applyjob record id
insert proc;
ProcessInstanceWorkitem pworkItem = new ProcessInstanceWorkitem();
pworkItem.ActorId = userinfo.getuserId();
pworkItem.OriginalActorId = userinfo.getuserId();
pworkItem.ProcessInstanceId = proc.id;
insert pworkItem;
@isTest
public class BatchSendEmailAlerts8Test{
public static testMethod void method1(){
List<Apply_Job__c> applyLst = new List<Apply_Job__c>();
set<Id> applyIds = new set<Id>();
Apply_Job__c apply = new Apply_Job__c();
apply.Status__c = 'Pending Approval';
apply.Qualification__c='B.pham';
apply.Next_Alert_Schduled_Date__c = system.today();
insert apply;
applyLst.add(apply);
Apply_Job__c apply1 = new Apply_Job__c();
apply1.Status__c = 'Pending Approval';
apply1.Qualification__c='B.pham';
apply1.Next_Alert_Schduled_Date__c= system.today();
insert apply1;
applyLst.add(apply1);
Apply_Job__c apply2 = new Apply_Job__c();
apply2.Status__c = 'Pending Approval';
apply2.Qualification__c='B.pham';
apply2.Next_Alert_Schduled_Date__c= system.today();
insert apply2;
applyLst.add(apply2);
for(Apply_Job__c apps:applyLst)
{
applyIds.add(apps.id);
}
ProcessInstance proc = new ProcessInstance();
proc.LastActorId = userinfo.getuserid();
proc.TargetObjectId = apply.id;//applyjob record id
insert proc;
system.debug('processInstance record inerted----'+proc.id);
ProcessInstanceWorkitem pworkItem = new ProcessInstanceWorkitem();
pworkItem.ActorId = userinfo.getuserId();
pworkItem.OriginalActorId = userinfo.getuserId();
pworkItem.ProcessInstanceId = proc.id;
insert pworkItem;
system.debug('processInstancework item record inerted----'+pworkItem.id);
List<ProcessInstanceWorkitem> pworkLst = [select id,ActorId,ProcessInstanceId,actor.email,ProcessInstance.TargetObjectId from ProcessInstanceWorkitem where ProcessInstance.TargetObjectId in: applyIds];
system.debug('pworkLst is ---------'+pworkLst.size());
BatchSendEmailAlerts8 batch = new BatchSendEmailAlerts8();
Test.StartTest();
Database.EexecuteBatch(batch);
Test.StopTest();
}
}
http://salesforce.stackexchange.com/questions/17981/processinstanceworkitems-not-created-when-running-an-approval-process-unit-test