You need to sign in to do that
Don't have an account?
learn sfdc 24
How to insert system.today(),createddate in testclass
school__c -->customObject
studentjoinage =system.today() - createddate; //its formula field which riturn number.
I written the batchclass,in that if(sch.studentjoinage__c==30) then send an email.
test.starttest
mybatchcls mb=new mybatchcls();
database.execute();
test.stoptest;
i get 40% codecoverage, in that start method ,finish methods r coverd but in execute method after if condition which means
messaging.singleemailmessage not coverd bcoze formula field.
i need help here to cover formula field.
studentjoinage =system.today() - createddate; //its formula field which riturn number.
I written the batchclass,in that if(sch.studentjoinage__c==30) then send an email.
test.starttest
mybatchcls mb=new mybatchcls();
database.execute();
test.stoptest;
i get 40% codecoverage, in that start method ,finish methods r coverd but in execute method after if condition which means
messaging.singleemailmessage not coverd bcoze formula field.
i need help here to cover formula field.
Account accInstance = new Account();
accInstance.Name = 'Test';
accInstance.NumberOfEmployees = 10;
insert accInstance;
accInstance = [SELECT Id, Quant__c FROM Account Where Name = 'Test'];
System.debug('>>>accInstance :' + accInstance);
Manually you cannot put value in formula field.
createddate=system.today()-30days;
system.today() - createddate.
Refer :
https://salesforce.stackexchange.com/questions/62/unit-testing-code-which-has-logic-around-the-createddate
http://releasenotes.docs.salesforce.com/en-us/spring16/release-notes/rn_apex_tests.htm#rn_apex_tests_setcreateddate
Test.setCreatedDate(a.Id, DateTime.newInstance(2012,12,12));
But you can give every answer a thumb up if that answer is helpful to you.
This will help keep the forum future users determine what answers are useful
Spring '16 release notes (http://docs.releasenotes.salesforce.com/en-us/spring16/release-notes/rn_apex_new_classes_methods.htm#rn_apex_new_classes_methods_changed_classes) document a new system method supporting this:
Steps :
Just create a new DateTime object
use Test.setCreatedDate to set the dateTime for the createdDate of that object
Use the below sample code :
Let me know if it helps.
Thanks and Regards,
Shiva RV
@Célio Xavier code is also the same.