You need to sign in to do that
Don't have an account?
VSK98
Test class for sample batch class
Hi All,
I am writing test class for batch class.........but it covered upto 50 % only ..........Here is batch class
Here is my test class
Adv thnx
Siv
I am writing test class for batch class.........but it covered upto 50 % only ..........Here is batch class
global class batchAccountUpdateSLA implements Database.Batchable<sObject> { global Database.QueryLocator start(Database.BatchableContext BC) { date d = system.today(); String query = 'SELECT Id,Name FROM Account where after1day__c = :d return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<Account> scope) { for(Account a : scope) { a.SLA__c= 'Gold'; } update scope; } global void finish(Database.BatchableContext BC) { } }
Here is my test class
@isTest public class batchAccountUpdateSLA_Test{ Static testmethod void batchAccountUpdateSLA_TestMethod(){ Date d = system.today().addDays(3); Account acc = new Account(); acc.name = 'Test'; acc.Fax = '12345'; insert acc; Test.StartTest(); batchAccountUpdateSLA bacth = new batchAccountUpdateSLA (); ID batchprocessid = database.Executebatch(bacth ); Test.StopTest(); } }Formula field is After1day code:
DATEVALUE(CreatedDate) + CASE( MOD(DATEVALUE(CreatedDate)- DATE(1900, 1, 7), 7), 0, 2, 1, 1, 2, 1, 3, 1, 4, 1, 5, 3, 6, 3, 0)
Adv thnx
Siv
From Spring '16, new method .setCreatedDate is available for testing:
Marek
All Answers
From Spring '16, new method .setCreatedDate is available for testing:
Marek
there is nice @bobbuzzard blog about it -> http://bobbuzzard.blogspot.co.uk/2016/01/salesforce-spring-16-createddate-and.html
My box is Spring '16 ..................
I tried it in my spring16 sandbox and it works fine