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

Update record in Apex or Trigger.
Hi All,
Can any help me How to update a Field in paritcular Table(object), i tried to update a Lead record, but i coud't set the id value.
ex,
Lead leadOldObject = ref for exsiting; //existing lead object ....
Lead l = new Lead();
l.LastName = l.LastName +'Its me';
l.id = new ID(leadOldObject.id); // if i commited this line getting error as no id was assigned for update objects
update l;
<end>
l.id = new ID(leadOldObject.id);
if i commited the above line getting error as no id was assigned for update throw
not commented means i compiler error on this line..
Thnx in advance!
l.LastName = leadOldObject.LastName +'Its me'; // this is correct line....
FYI
The id field cannot be written, you must query (if you don't have the object already loaded) the object first, modify it, then update .
Example:
Lead MyLead = [Select Id, Name from Lead where Name = 'Norman Bates'];
MyLead.Name = 'Modified Norman';
update MyLead;
Bruno.
Fetch the record from the object using query then update the field from that object.
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi