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
MMA_FORCEMMA_FORCE 

Trigger Help please

I have a field named Total Students... and trying to do a count() on the object but can not get it to work...

It keeps bringing up this error:

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger TTLs caused an unexpected exception, contact your administrator: TTLs: execution of AfterUpdate caused by: System.Exception: Record is read-only: Trigger.TTLs: line 7, column 9

 

trigger TTLs on Account (after update) { List<Account> udte = new List<Account>(); Integer accs; accs=[Select count() from Account where RecordType.Name='Student']; for(Account hr: trigger.old) { hr.Total_Students__c=accs; htoUpdte.add(hr); } }

 Yes I check the field level security, everything is editable about this field...

Where am I going wrong...

 

 

 

TheReportDoctorTheReportDoctor
The trigger.old is read-only.  You are trying to set a value to the old trigger.
minku1986minku1986
did anybody find a solution to this problem?
minku1986minku1986

    
    I am trying to add some data to a field.
    
    But it gives me this error...
    
    Apex trigger handleProjectManagerLookup caused an unexpected exception, contact your administrator: handleProjectManagerLookup: execution of AfterUpdate caused by: System.Exception: Record is read-only: Trigger.handleProjectManagerLookup: line 7, column 6
Message Edited by minku1986 on 03-03-2010 06:52 PM
krish_krish_

I think the below code will work.

 

 

trigger handleProjectManagerLookup1 on Timesheet__c (after insert) { for(Timesheet__c objTimesheet:Trigger.New) { List<TimeEntry__c> TE = [Select t.Time__c, t.Notes__c From TimeEntry__c t WHERE t.Time__c = 23.00]; for (TimeEntry__c temp : TE){ temp.Notes__c = 'Meenakshi'; } update TE; } }

 

 

 

minku1986minku1986

When I try to create a new timesheet record it still gives errors:

 

Apex trigger handleProjectManagerLookup1 caused an unexpected exception, contact your administrator: handleProjectManagerLookup1: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id a08A0000000r3A0IAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, handleProjectManagerLookup: execution of AfterUpdate caused by: System.Exception: Record is read-only Trigger.handleProjectManagerLookup: line 7, column 6: []: Trigger.handleProjectManagerLookup1: line 9, column 3

 

 

Whereas trying to create a new timeentry record gives the same old Record is readonly error 

 

 

 

 

krish_krish_

check the Timesheet list size

If the size() > 1 then update the object.