You need to sign in to do that
Don't have an account?
Test for Trigger
Hi guys! I've written my first trigger, which works in my sandbox, but I can't successfully write a test for it. The field that it filters on is a read only formula field. Any help would be greatly appreciated!
Thanks much!
trigger accountRankings on Account(after insert, after update, after delete){ for(Account acc : trigger.new) { //checking if the value is changed if(acc.VAROrderPointsYTD__c != Null && (trigger.isInsert || (trigger.newMap.get(acc.id).VAROrderPointsYTD__c != trigger.oldMap.get(acc.id).VAROrderPointsYTD__c))) { break; } else return; } //rank top 100 accounts for more accounts change the row limit List<Account> accounts = [Select VAROrderPointsYTD__c, Point_Ranking__c from Account Where RecordType.Name = 'Richmond VAR' ORDER BY VAROrderPointsYTD__c DESC limit 100]; Integer rank = 1; for (Account account : accounts) { account.Point_Ranking__c = rank; rank++; } update accounts; }
All Answers
Read Only formula fields return values only when queried. So in your test class populate the fields with your test data that constitute the formula for that field and this should solve your problem.
I this answer help please do not forget to mark this as a best answers
Thanks
Siddharth