+ Start a Discussion
ArikArik 

Test Class Error

I am stuck on the test class.....Any help appreciated:

 

Here is the Trigger:

 

trigger     CICDocumentsObjectionDeadline on rethink2__Closing__c (before update) {

    ////////////////////////////////////
    // This trigger detects the change of the TestCheckbox field
    // and creates an Event
    ////////////////////////////////////
   
    if(trigger.isUpdate && trigger.isBefore) {
       
        // Create empty List to hold new Events (bulk DML)
        List<Event> lstNewEvents = new List<Event>();
       
        for(rethink2__Closing__c a : trigger.new) {
           
            // Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
            if(a.CIC_Documents_Objection_Deadline_Checkbo__c == true && a.CIC_Documents_Objection_Deadline_Checkbo__c != trigger.oldMap.get(a.Id).CIC_Documents_Objection_Deadline_Checkbo__c) {
               
                // Set Start Date
                Date dteStart = a.CIC_Documents_Objection_Deadline__c;
               
                // Create Event
                Event newEvent = new Event();
                newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
                newEvent.WhatId = a.Id; // Sets the Account as the Event's "Related To"
                newEvent.Subject = 'CIC Documents Objection Deadline';
                newEvent.ActivityDate = a.CIC_Documents_Objection_Deadline__c;
                newEvent.IsAllDayEvent = true;
               
                lstNewEvents.add(newEvent);
               
            }
        }
       
        if(lstNewEvents.size() > 0) { insert lstNewEvents; }
       
    }
    
}

Here is the Test Class that gives error

Error: Compile Error: Expression cannot be assigned at line -1 column -1

 

@isTest
private class testCICDocumentsObjectionDeadline{

    public static testMethod void unitTestCICDocumentsObjectionDeadline() {

        rethink2__Closing__c.Name = new Name();
        rethink2__Closing__c.Name = 'Test Closing';
rethink2__Closing__c.CIC_Documents_Objection_Deadline__c = Date.newInstance(2011,5,1);


        insert rethink2__Closing__c.Name;

        test.startTest();

        rethink2__Closing__c.CIC_Documents_Objection_Deadline_Checkbo__c = true;
        update rethink2__Closing__c.Name;

        test.stopTest();

    }
}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

 

try this code

@isTest
private class testCICDocumentsObjectionDeadline{
public static testMethod void unitTestCICDocumentsObjectionDeadline() {
rethink2__Closing__c retink=new rethink2__Closing__c(name='test', CIC_Documents_Objection_Deadline__c= Date.newInstance(2011,5,1), CIC_Documents_Objection_Deadline_Checkbo__c=false);
insert retink;
test.startTest();
retink.CIC_Documents_Objection_Deadline_Checkbo__c = true;
update retink;
test.stopTest();
}
}

 

Apologies for the last post

All Answers

Navatar_DbSupNavatar_DbSup

Hi,
Try the below code for your test method:

 

@isTest
private class testCICDocumentsObjectionDeadline{
public static testMethod void unitTestCICDocumentsObjectionDeadline() {
rethink2__Closing__c retink=new rethink2__Closing__c(name=’test’, CIC_Documents_Objection_Deadline__c= Date.newInstance(2011,5,1), CIC_Documents_Objection_Deadline_Checkbo__c=false);
insert retink;
test.startTest();
rethink2__Closing__c.CIC_Documents_Objection_Deadline_Checkbo__c = true;
update retink;
test.stopTest();
}
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

ArikArik

Thx - I get this error:

 

Error: Compile Error: line 4:58 no viable alternative at character '’' at line 4 column 58

 

Any thoughts

Navatar_DbSupNavatar_DbSup

Hi,

 

try this code

@isTest
private class testCICDocumentsObjectionDeadline{
public static testMethod void unitTestCICDocumentsObjectionDeadline() {
rethink2__Closing__c retink=new rethink2__Closing__c(name='test', CIC_Documents_Objection_Deadline__c= Date.newInstance(2011,5,1), CIC_Documents_Objection_Deadline_Checkbo__c=false);
insert retink;
test.startTest();
retink.CIC_Documents_Objection_Deadline_Checkbo__c = true;
update retink;
test.stopTest();
}
}

 

Apologies for the last post

This was selected as the best answer
ArikArik

Thank You Very Much !!!