0
trigger GudMorning on Class__c (before insert,after insert) {
    if(trigger.isbefore){
        for(Class__c c1 : Trigger.new){
            c1.State__c = 'AP';
        }          
    } else {
        List<Class__c> crlst = new List<Class__c>();
        if(trigger.isafter){
            for(Class__c cr : Trigger.new){
                cr.State__c = 'TN' ;
                //insert cr;
                crlst.add(cr);
            }
        }
    }
}
1
  • 3
    If the truigger is ran after insert or update, you can no longer change the values in the Trigger.new map. So the line cr.State__c = 'TN'; is where you try to change a value in the Trigger.new map, which throws the error. I really don't see what your trigger is trying to achieve though, maybe you can update your question to elaborate on the goal.
    – rael_kid
    Apr 19 '14 at 16:55
1

Change your trigger to before insert only (remove after insert) and it will work. The bit you have after insert should be done before.

Having said that, your trigger as written just doesn't make sense. What are you trying to do?

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.