• Pranay Dhapodkar
  • NEWBIE
  • 5 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I'm getting this error when I try to update a contact record:

 

Review all error messages below to correct your data.
Apex trigger ContactStageTrigger caused an unexpected exception, contact your administrator: ContactStageTrigger: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.ContactStageTrigger: line 6, column 1

 

Here is my Code:

 

trigger ContactStageTrigger on Contact (after insert, after update) {

    Contact myContact = trigger.new[0];
    Account myAccount = [SELECT OwnerId FROM Account WHERE Id = :myContact.AccountId];
    if(myContact.Status__c == 'Prospect'){
        myContact.OwnerId = myAccount.OwnerId;
        update myContact;
    }
 }