You need to sign in to do that
Don't have an account?
Akash Garg 2
Want to delete opportunities record whose createddateis 365 days ago or before
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(); } }
Try this Code-
Thanks
Rupal Kumar
http://Mirketa.com
All Answers
Try this Code-
Thanks
Rupal Kumar
http://Mirketa.com
Now my code is 100% coverage.
Can you do me a favor as i'm a beginner developer.
Can you tell me why we use
Can you explain why the process from starttest to stop test??
Once again very thanks to you.
Test.startTest() and Test.stopTest() exist primarily to allow you to reset the governor limits within the context of your test execution and to be able to test asynchronous methods. These two statements cannot be called more than once within a testMethod. They are not required to be used but in some situations may be critical. Asynchronous (@future) calls made during the test are also finalized when you call Test.stopTest() allowing you to test the results of asynchronous behavior in your code.
However you can go and check in the Scheduled Jobs that your class has been alrady scheduled or not .
Setup -> Monitoring -> Schduled Jobs
Here you will get all the classes that has been scheduled.
If you want to reschedule it than delete it from here and schedule it again
Please mark it as the best answer if it helpful to you.
Thanks
Rupal kumar
http://mirketa.com