You need to sign in to do that
Don't have an account?
Priya134
Test Class on Event Trigger
Hello Everyone!
How do i write test class for the trigger below.
How do i write test class for the trigger below.
Trigger AccountEventTrigger on Event (Before Insert) { /****************************************************************************** It controlls the creation of Events from accounts which are yet to be approved. *******************************************************************************/ list<Id> accountIds = new list<Id>(); Map<Id,Account> accMap = new Map<Id,Account>(); for(Event Event: Trigger.new){ if(Event.whatId != null && String.valueof(Event.whatId).startsWith('001')) accountIds.add(Event.whatId); } if(!accountIds.isEmpty()){ for(Account acc : [select id,Submitted_for_Approval__c from Account where id in : accountIds]){ accMap.put(acc.id,acc); } for(Event Event: Trigger.New){ if(Event.whatId != null && accMap.containsKey(Event.whatId) && accMap.get(Event.whatId).Submitted_for_Approval__c!= false) Event.addError('New Event Cannot be Created'); } } }
Please refer the below code and mark this as solved if this works for you.
All Answers
Here is the code
@isTest
private class AccountEventTrigger_Test {
private static testmethod void testcase1(){
Account a = new Account();
a.Name='Test' ;
Insert a ;
Event event = new Event( Subject = 'Test Event', StartDateTime=System.today(), EndDateTime=System.today()+5);
event.WhatId = a.Id;
insert event;
}
}
I ran the test class. it fails with this error.
Please refer the below code and mark this as solved if this works for you.