You need to sign in to do that
Don't have an account?
Michael Hedrick 2
Test code for
Hello All,
I have been going in circles with this code for 2 days and received some help but I am still at a loss. The code below looks for Contracts where the checkbox Automatic_renewal__c = TRUE AND the field Contract_End_Date_Current__c = Yesterday. I have tried to create a test class with data but my test coverage is '0'. All of the Contracts are associated to an Account. So can I jsut have a single account with multiple Contracts assoicated to it? What is the best way to confirm that the contract data was created with the desired date?
Any help would be greatly appreciated.
Cheers,
M
Global class ContractUpdateContractRenewalStartDate implements Schedulable {
// Allow tests to see the variable, but not "normal" code
@TestVisible Date contractdate = System.today().addDays(-1);
global void execute(SchedulableContext sc) {
list<Contract> Contractupdate = [SELECT Id, Contract_Start_Date_Current__c,Contract_End_Date_Current__c FROM Contract WHERE Automatic_renewal__c = TRUE AND Contract_End_Date_Current__c =: contractdate ];
for(Contract c: Contractupdate)
{
c.Contract_Start_Date_Current__c = System.today();
}
update Contractupdate;
}
}
I have been going in circles with this code for 2 days and received some help but I am still at a loss. The code below looks for Contracts where the checkbox Automatic_renewal__c = TRUE AND the field Contract_End_Date_Current__c = Yesterday. I have tried to create a test class with data but my test coverage is '0'. All of the Contracts are associated to an Account. So can I jsut have a single account with multiple Contracts assoicated to it? What is the best way to confirm that the contract data was created with the desired date?
Any help would be greatly appreciated.
Cheers,
M
Global class ContractUpdateContractRenewalStartDate implements Schedulable {
// Allow tests to see the variable, but not "normal" code
@TestVisible Date contractdate = System.today().addDays(-1);
global void execute(SchedulableContext sc) {
list<Contract> Contractupdate = [SELECT Id, Contract_Start_Date_Current__c,Contract_End_Date_Current__c FROM Contract WHERE Automatic_renewal__c = TRUE AND Contract_End_Date_Current__c =: contractdate ];
for(Contract c: Contractupdate)
{
c.Contract_Start_Date_Current__c = System.today();
}
update Contractupdate;
}
}
I would recommend you to write the code using Batch Apex as we are not sure about the number of records it will return. Hence use the below code:
Here I considered:
==> Corrected the Code.
==> Implemented the Test Class
==> Tested the code in DE environment.
Also Tested the code in my DE environment and it looks good.
Below is the Test Class:
Also Verified the code coverage:
Please do let me know if it helps you.
Regards,
Mahesh
All Answers
I would recommend you to write the code using Batch Apex as we are not sure about the number of records it will return. Hence use the below code:
Here I considered:
==> Corrected the Code.
==> Implemented the Test Class
==> Tested the code in DE environment.
Also Tested the code in my DE environment and it looks good.
Below is the Test Class:
Also Verified the code coverage:
Please do let me know if it helps you.
Regards,
Mahesh
I will add the 2 additional fields when I create the contract and hopefully it will work...
Kind Regards,
M
Cheers,
Michael