You need to sign in to do that
Don't have an account?

i want to write a trigger to update teh description field on account if condition satify
i want to update the account filed Desc when any new account is created or update with the desc filed contain 12345
here is my code it not allowing me to create record!!!!!
Not allowing to crete record showing error
//updateDesc: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Trigger.updateDesc: line 11, column 1
Thanks is advance
trigger updateDesc on Account (after insert,after update) {
List<Account> accList = new List<Account>();
for(Account acc : Trigger.new)
if(acc.Description =='12345')
{
Account accountobj = new Account();
accountobj.Description=' Test trigegr';
accList.add(accountobj);
}
update accList;
}
You have your account record already from the Trigger.new list and you are itterating over it with 'acc'.
A few other things I would do, is create a class and method to handle the logic, and pass Trigger.new into that. Keeps the logic out of the trigger and gives you access to more features such as 'with sharing'. But the basics are almost there! :)
thanks fro reply
eroror while inserting the record
updateDesc: execution of AfterInsert caused by: System.FinalException: Record is read-only Trigger.updateDesc: line 7, column 1
errror again
updateDesc: execution of BeforeInsert caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old Trigger.updateDesc: line 11, column 1