0
@isTest
private class TestRejectDoubleBooking{
    public void TestSingleBooking(){
      static testmethod void TestSingleBooking() {
    Datetime now = System.now();

    Speaker__c speaker = new Speaker__c(First_Name__c='John', Last_Name__c='Smith');
    insert speaker;

    Session__c session = new Session__c(Name='Some Session', Session_Date__c=now);
    insert session;

    Session_Speaker__c assignment =
    new Session_Speaker__c(Session__c=session.Id, Speaker__c=speaker.Id);

    Database.SaveResult result = Database.insert(assignment, false);

    System.assert(result.isSuccess());
}   
    }

}
  • 2
    Welcome to SFSE! Your question looks like a message that you are getting compile error. Can you please specific on what problem you are facing or what is your doubt/question. Please go through How to Ask section to understand how to ask. – Ashwani Sep 20 '16 at 10:03
1

You cannot declare a method within a method. Remove this line:

public void TestSingleBooking() {

And also remove the corresponding closing bracket }.

Correct Code:

@IsTest
class TestRejectDoubleBooking
{
    static testMethod void testSingleBooking()
    {
        // test code here
    }
}

What you are doing instead is trying to declare a method within a method, as stated above. Note also that your methods must be declared testmethod or annotated with @IsTest in order to actually run.

Incorrect Code:

@IsTest
class TestRejectDoubleBooking
{
    public void testSingleBooking()
    {
        static testMethod void testSingleBooking()
        {
            // test code here
        }
    }
}

I also find that careful, consistent use of indentation can make these types of problems much more clear.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.