• Prasad Karagaonkar
  • NEWBIE
  • 10 Points
  • Member since 2017
  • Specialist
  • Appirio

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

trigger AddDesctoAccount on Account (Before Update) {
 
    Id userId= userinfo.getUserId();
    User UserDetails = [select Id,Username from User where Id= :userId ];
    String uName= UserDetails.Username;
   List<Account> actToUpdate = new List<Account>();
    for(Account acc: Trigger.new){
        actToUpdate.add(acc);
    }
    
    for(Account act: actToUpdate){
        act.Description=uName;
    }
    
    database.update(actToUpdate,false);
    
}




Output:

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger AddDesctoAccount caused an unexpected exception, contact your administrator: AddDesctoAccount: execution of BeforeUpdate caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old: Trigger.AddDesctoAccount: line 15, column 1



Please Help me with the code.


Thank You,
Prasad
//  Code :

trigger AddDesctoAccount on Account (Before Update) {
 
    Id userId= userinfo.getUserId();
    User UserDetails = [select Id,Username from User where Id= :userId ];
    String uName= UserDetails.Username;
   List<Account> actToUpdate = new List<Account>();
    for(Account acc: Trigger.new){
        actToUpdate.add(acc);
    }
    
    for(Account act: actToUpdate){
        act.Description=uName;
    }
    
    database.update(actToUpdate,false);
    
}




Output:

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger AddDesctoAccount caused an unexpected exception, contact your administrator: AddDesctoAccount: execution of BeforeUpdate caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old: Trigger.AddDesctoAccount: line 15, column 1



Please Help me with the code.


Thank You,
Prasad