I need help on the test class for this schedule on Opportunity. Getting error on below code with comment and only 35% coverage code.
global class OppJob_Task_1stPhoneFollowup implements Schedulable {
global void execute(SchedulableContext ctx) {
List<Opportunity> oppList = [Select ID, Post_1st_Follow_Up_cycle_days_ROPP__c, owner.id, owner.isactive,
Master_Opportunity__c, X2nd_Follow_Up_cycle_days_ROPP__c
from Opportunity
where Master_Opportunity__c = null and
Renewal_Stage__c not in ('Renewed','Canceled','Pending Region') and
X2nd_Follow_Up_cycle_days_ROPP__c = NEXT_N_DAYS:1 ];
// X2nd_Follow_Up_cycle_days_ROPP__c = today ];
List<Task> taskList = new List<Task>();
For(Opportunity opp : oppList) {
if(opp.Owner.isActive == true) {
Task newTask = new Task(
WhatId = opp.Id,
OwnerId = opp.OwnerId,
ActivityDate = opp.X2nd_Follow_Up_cycle_days_ROPP__c.adddays(1) ,
Subject = '1st Phone Follow-up',
Description = 'Call customer for 1st Phone Follow-up');
taskList.add(newTask);
}
}
system.debug('tasklink'+ tasklist.size());
if (tasklist.size()>0){
insert taskList;
}
}}
Test Class:
@isTest
public class OppJob_Task_1stPhoneFollowupTest {
static testmethod void testScheduledJob() {
String CRON_EXP = '0 0 0 3 9 ? 2020';
Account ac = TestingDataUtil.CreateAccounts(1)[0];
insert ac;
Opportunity opp = TestingDataUtil.CreateOpportunities(1, ac.Id, 'Renewal')[0];
opp.SAP_Contract_Amount__c = 1200;
opp.Master_Opportunity__c = null;
opp.Renewal_Stage__c = 'Invoice Sent';
opp.OwnerId = 'XXXXXXXXXX';
insert opp;
Test.StartTest();
//Schedule the Test Job
String jobID = System.schedule('OppJob_Task_1stPhoneFollowup123', CRON_EXP, new OppJob_Task_1stPhoneFollowup());
Task newTask = new Task(
WhatId = opp.Id,
OwnerId = opp.OwnerId,
ActivityDate = date.valueOf('2019-12-24 11:30:20'),
Subject = '1st Phone Follow-up',
Description = 'Call customer for 1st Phone Follow-up');
insert newtask;
/**getting an error on this**
Unexpected token 'opp.Id'
Missing 'IDENTIFIER' at ']'
expecting a colon, found 'opp.Id'*
*/
//error on this below//
List<Task> lt = [SELECT Id, whatID FROM Task where whatid = opp.Id];
Test.stopTest();
}
}