Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

This question already has an answer here:

I'm new to Apex code, got below error Error: Invalid Data. Review all error messages below to correct your data. Apex trigger PositionTrigger caused an unexpected exception, contact your administrator: PositionTrigger: execution of AfterInsert caused by: System.FinalException: Record is read-only: Trigger.PositionTrigger: line 4, column 1

trigger PositionTrigger on Position__c (after insert) {
  Position__c ThePosition = trigger.new[0];
  if(ThePosition.Days_Open__c>90){
    ThePosition.Educational_Requirements__c='Featured';
    update ThePosition;
  }
}

please let me know the solution.

share|improve this question

marked as duplicate by ca_peterson, Samuel De Rycke, Bachovski, LaceySnr Mar 5 at 0:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

When you are doing an After trigger, Trigger.new is read only. If you want to make changes to it, then it is best to do it in a Before trigger.

Also, your trigger is not bulkified. If more than one record is updated at a time, then only the first one will be evaluated. See http://wiki.developerforce.com/page/Best_Practice%3A_Bulkify_Your_Code and search for other examples.

share|improve this answer

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