
trigger EZAutoNumber on Zone__c (before insert) {
//Create List that will give us the highest number in EZ_Auto_Number__c field and putting that number in a variable called "maxlead"
list<Zone__c> l= [SELECT Id, Name, EZ_Auto_Number__c FROM Zone__c where EZ_Auto_Number__c !=:null order by EZ_Auto_Number__c desc limit 1];
decimal maxlead = l[0].EZ_Auto_Number__c + 1;
for(Zone__c li:Trigger.new) {
//Looking for only RZ Record Type
if(li.Program_Type__c == 'EZ'){
//Updating EZ_Auto_Number__c to maxlead+1
li.EZ_Auto_Number__c = Integer.valueOf(maxlead);
}
break;
}
}
When I try the test class below I get this error: System.ListException: List index out of bounds: 0
Trigger.CRAAutoNumber: line 5, column 1
I think that it is because the list that the list in the trigger does not return any records from the test class. How would I go about making the list generate a result in the test class?
@isTest
public class TestEZAutoNumber {
static testMethod void insertNewEZZone(){
Zone__c ez = new Zone__c();
ez.Program_Type__c = 'EZ';
insert ez;
}
}
6 Antworten
I believe you have not inserted all valid fields like madatory fields or system fields , if name field is not auto number you should pass the value in that also