You need to sign in to do that
Don't have an account?
srikanth bellamkonda
how to handle Account History in a test class to cover up code coverage
Hi, Am writing a test class to cover up code coverage, but the AccoutHistory lines are not coverd in the class, how to handle that.
Just assume that, I have a Class chat_piexyz, in that class i have a method 'PopulateChartData()' , In that method we have a if condition like
But in Test class i wrote a class like this
But it is not covering the If condition(Account history) in the class Chat_piexyz.
I run the Query in Query log in developer console, it shows account history data With Respect To Account id.
Just assume that, I have a Class chat_piexyz, in that class i have a method 'PopulateChartData()' , In that method we have a if condition like
public With Sharing class Chat_piexyz { public Chat_piexyz (ApexPages.StandardController controller) { // some data } Public void PopulateChartData() { List<AccountHistory> accHistory = [Select oldvalue,newvalue, createddate from AccountHistory where AccountId =: accId AND field = 'M_AUM__c' ORDER BY createdDate ASC]; if(!accHistory.IsEmpty()){ // do some thing } }
But in Test class i wrote a class like this
@isTest public class Chart_piedata_Test { static testMethod void chatContoller() { Account Acc = new Account(); Acc.Name='Test123'; acc.M_AUM__c = 4000; insert Acc; acc.M_AUM__c = 20000; update acc; system.debug('Test Account++'+acc); acc.M_AUM__c = 1000; update acc; system.debug('Update : '+[select oldvalue, newvalue, createddate from AccountHistory where (AccountId = :acc.id and field = 'M_AUM__c') order by createdDate]); ApexPages.StandardController sc = new ApexPages.StandardController(acc); Chat_piexyz controller =new chat_piexyz(sc); controller.PopulateChartData(); } }
But it is not covering the If condition(Account history) in the class Chat_piexyz.
I run the Query in Query log in developer console, it shows account history data With Respect To Account id.
[1] http://salesforce.stackexchange.com/questions/4007/is-it-possible-to-test-apex-that-relies-on-field-history-tracking