function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shubham SengarShubham Sengar 

trigger problem 2

trigger updaterecord on Account (before insert){

for(Account acc: trigger.new){
Account acc1;
acc1.Type= 'prospecting';
update acc1;
}
}

its give error when m going to insert..
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger updaterecord caused an unexpected exception, contact your administrator: updaterecord: execution of BeforeInsert caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old: Trigger.updaterecord: line 7, column 1
 
Best Answer chosen by Shubham Sengar
AmrenderAmrender
Hi Shubham

You are trying to update an Account which is not inserted yet. Try below code
trigger updaterecord on Account (before insert){

for(Account acc: trigger.new){
//Account acc1;
acc.Type= 'prospecting';
//update acc1;
}
}

Let me know if it helps you.

Regards
Amrender