• Ramnath kumar 9
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
The following is a trigger that saves correctly to Sandbox.  In it, I want to set the PP_CLIENT_DIR_VP__c to a specific value after an update or creation of an Account record.
 

Trigger UpdateTMID on Account (after insert, after update)

{

List<Account> acctList = new List<Account>();

for (Account acct:Trigger.new)

{

Integer i = 1;

Account a = new Account(Id = acct.Id);

system.debug('This is the number of times it is has gone through the loop' +i);

acct.PP_CLIENT_DIR_VP__c = 'JC13';

acctList.add(acct);

i++;

}

// update the Accounts

update acctList;

}

 

When I attempt to update an Account, however, I receive an error System.Exception: Record is read-only.  The curious thing is 1) I own the Account record and 2) I have written a similar trigger on Contract without this issue.

Additionally, I am setting Account a = new Account(Id = acct.Id); even though I don't intend to create a new Account but rather update the Account that has triggered.  Is this correct?  Incidentally, when I comment out this line, I either get the read-only error or the for loops more than once for one record update.

Any thoughts?

  • January 10, 2008
  • Like
  • 0