You need to sign in to do that
Don't have an account?
F.H.Kazmi
Unable to update lead using trigger
trigger LeadTrigger on Lead (after insert) {
//works dsdcc
for (Lead lea : Trigger.New)
{
lea.City = 'New York';
update lea;
}
}
/*error when create lead error is:
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger LeadTrigger caused an unexpected exception, contact your administrator: LeadTrigger: execution of AfterInsert caused by: System.Exception: Record is read-only: */
Yes, that trigger is an "after" trigger (after insert to be exact) and an "after" trigger can't update the Lead records that initiated the request. If you change the trigger to a "before" trigger, this code should work.
trigger LeadTrigger on Lead (before insert) { for (Lead lea : Trigger.New) { lea.City = 'New York'; } }