You need to sign in to do that
Don't have an account?
Salesforce Admin 78
Want to Delete Opportunities record whose created date is 200 days ago or more
I have written a apex class with test class both are running but my code coverage is only 66%.Please help to solve the problem.
Apex class-
Test Class-
Apex class-
global class Deleteoppotest implements Schedulable{ global void execute(SchedulableContext SC) { deleteoppo(); } public static void deleteoppo() { for(List<opportunity> objoppo : [SELECT Id FROM opportunity WHERE CreatedDate <= :(Date.Today() - 200) LIMIT 10]) { delete objoppo; } }
Test Class-
@isTest private class Deleteoppotestcls { static testMethod void myUnitTest() { // TO DO: implement unit test Opportunity op = new Opportunity(); op.Name = 'test1'; op.StageName = 'Qualified'; op.CloseDate = Date.Today(); op.Description ='testingoppotestcls'; op.Business_Type__c = 'Domestic'; insert op; Deleteoppotest.deleteoppo(); } }
global class Deleteoppotest implements Schedulable{
global void execute(SchedulableContext SC) {
for(List<opportunity> objoppo : [SELECT Id FROM opportunity WHERE CreatedDate <= :(Date.Today() - 200) LIMIT 10])
delete objoppo;
}
}
TESTCLASS:
100% code coverage
@isTest
public class Deleteoppotestcls {
static testmethod void deleteopp(){
opportunity opp = new opportunity();
opp.Name = 'delete record';
opp.CloseDate = system.today();
opp.StageName = 'Prospecting';
insert opp;
Deleteoppotest del = new Deleteoppotest();
string s2 ='0 02 20 * * ?';
Test.startTest();
system.schedule('Test1', s2, del);
Test.stopTest();
}
}
All Answers
try this:
Thanks
Ankur Saini
http://mirketa.com
global class Deleteoppotest implements Schedulable{
global void execute(SchedulableContext SC) {
for(List<opportunity> objoppo : [SELECT Id FROM opportunity WHERE CreatedDate <= :(Date.Today() - 200) LIMIT 10])
delete objoppo;
}
}
TESTCLASS:
100% code coverage
@isTest
public class Deleteoppotestcls {
static testmethod void deleteopp(){
opportunity opp = new opportunity();
opp.Name = 'delete record';
opp.CloseDate = system.today();
opp.StageName = 'Prospecting';
insert opp;
Deleteoppotest del = new Deleteoppotest();
string s2 ='0 02 20 * * ?';
Test.startTest();
system.schedule('Test1', s2, del);
Test.stopTest();
}
}