You need to sign in to do that
Don't have an account?
Trigger Test Coverage : Error message Only top-level class methods can be declared static
I have copied some trigger test code:
@isTest
private class EventTester {
static testMethod void myUnitTest() {
//COMMENT: First, prepare Dummy Account for relating to Event
Account acct1 = new Account(name='test account1',Type='Customer');
insert acct1;
//COMMENT: First, prepare Dummy Event
Event EventToCreate = new Event(WhatId=acct1.Id,Subject='TESTING',StartDateTime=Today());
insert EventToCreate;
//COMMENT: Inserting the event with a start date value should have caused your trigger to fire which means you can move on to the verification steps
//Cont'd: however, if you have a trigger based on updating or something, be aware that you would perform that action before verification and AFTER
//Cont'd: inserting your dummy records inside of the test class.
//COMMENT: Verify correct action using System asserts (these make sure your trigger did what it is supposed to)
//COMMENT: first, we locate the Event that has been updated (as opposed to the event that was inserted, because the trigger has changed that origianl event
Event EvtUpd = [select UsableDueDate__c, StartDateTime from Event where id = :EventToCreate.Id];
//COMMENT: then we assert that the field we updated equals the field it was updated from
System.assert(EvtUpd.UsableDueDate__c == EventToCreate.StartDateTime);
}
}
But when I try and un it I get the above error.
Any help much appreciated ! Thanks.
Make the Class to public
Top-level type must have public or global visibility..!
If this makes your solution, then mark it as solution for other's reference..!
Hi Thanks for responding. Yes I think you are right, it does want to be a public class but simply changing the class to public does not solve my problem if, as I have been doing, I run the code in the normal code window. But I do solve it if I select Classes from the Setup Entity Type section of the developer console, give the class a name and then paste in exactly the same code. If I then select tests and then select the test class I've just created run it it runs perfectly. So what I think I've learned is that you can't create test classes (or all classes ?) in the normal developer window. Please correct me if I'm wrong.
Here is the code
Now all I've got to do is sort out the coverage... !
Thanks again.
Hi peter
Notable point..!
Thanks for sharing