You need to sign in to do that
Don't have an account?
test class for batch apex which adds oppournitiy records to account record
Hi i have a senario where i should write a batch class to add oppournities whose stage is need analysis and type is new oppournity and Age of oppurnity__c should be greater than 15 days ,My functionality is working fine but test class is not getting code coverage 100 percentage
So can anyone helpme to find out the problem
Batch class :
global class Batchforaddingoppournitytoaccount implements Database.Batchable<sobject>{
global Database.QueryLocator start(Database.BatchableContext BC){
string oppRecords = 'SELECT id, Name, StageName, Type, Age_of_oppournity__c FROM Opportunity';
return Database.getQueryLocator(oppRecords);
}
global void execute(Database.BatchableContext BC , List<Opportunity> oppList){
string addingRecords = Label.Account_Record; // holding my account id in custom label//
List<Opportunity> oppournityListupdate = new List<Opportunity>();
for(Opportunity eachoppournity : oppList){
if(eachoppournity.Type == 'New Opportunity' && eachoppournity.StageName == 'Needs Analysis' &&
eachoppournity.Age_of_oppournity__c >= 15){
eachoppournity.AccountId = addingRecords;
oppournityListupdate.add(eachoppournity);
}
}
if(oppournityListupdate.size() > 0){
update oppournityListupdate;
}
}
global void finish(DataBase.BatchableContext BC){
}
}
Test Class :
@isTest
public class Testforbatchoppournityrecords_TC {
public static testMethod void oppournityRecordstest(){
string accountRecordid = Label.Account_Record;
List<Opportunity> updatingOppournities = new List<Opportunity>();
Opportunity opp = new Opportunity ();
opp.Name= 'smart mobiles';
opp.Type ='New Business';
opp.StageName = 'Needs Analysis';
opp.CloseDate=date.today().addMonths(3);
insert opp;
test.startTest();
Batchforaddingoppournitytoaccount b = new Batchforaddingoppournitytoaccount();
DataBase.executeBatch(b);
test.stopTest();
}
}
These are the lines that are not covered by my test class
eachoppournity.Age_of_oppournity__c >= 15){
eachoppournity.AccountId = addingRecords;
oppournityListupdate.add(eachoppournity);
update oppournityListupdate;