function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ArikArik 

APEX Class Failure

Hi all -

 

This is my test class:

 

@isTest
private class testAutomaticFollowUp {

    public static testMethod void unitTestAutomaticFollowUp() {

        Contact acct = new Contact();
        acct.Name = 'Test Contact';
acct.Follow_Up_Date__c = Date.newInstance(2011,5,1);


        insert acct;

        test.startTest();

        acct.Follow_Upcheckbox__c = true;
        update acct;

        test.stopTest();

    }
}

 

I get the error:

 

Error: Compile Error: Field is not writeable: Contact.Name at line 7 column 9

 

Here is the Trigger:

 

trigger AutomaticFollowUp on Contact (before update) {

    ////////////////////////////////////
    // This trigger detects the change of the Followup 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(Contact a : trigger.new) {
            
            // Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
            if(a.Follow_Upcheckbox__c == true && a.Follow_Upcheckbox__c != trigger.oldMap.get(a.Id).Follow_Upcheckbox__c) {
                
                // Set Start Date
                Date dteStart = a.Follow_Up_Date__c;
                
                // Create Event
                Event newEvent = new Event();
                newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
                newEvent.WhoId = a.id; // Sets the Contact as the Event's Name
                newEvent.Whatid = a.Deal__c;
                newEvent.Subject = a.Follow_Up_Reason__c;
                newEvent.ActivityDate = a.Follow_Up_Date__c;
                newEvent.IsAllDayEvent = true;
                
                lstNewEvents.add(newEvent);
                
            }
        }
        
        if(lstNewEvents.size() > 0) { insert lstNewEvents; }
        
    }

}

Any Ideas or help - more then appreciated


Thanks in advance


Best Answer chosen by Admin (Salesforce Developers) 
uptime_andrewuptime_andrew

Try: 

 

        Contact acct = new Contact();
        acct.FirstName = 'Test';
        acct.LastName  = 'Contact';
acct.Follow_Up_Date__c = Date.newInstance(2011,5,1);

        insert acct;

 

All Answers

uptime_andrewuptime_andrew

Try: 

 

        Contact acct = new Contact();
        acct.FirstName = 'Test';
        acct.LastName  = 'Contact';
acct.Follow_Up_Date__c = Date.newInstance(2011,5,1);

        insert acct;

 

This was selected as the best answer
ArikArik

100% Test Coverage Thank You !!!!