After trigger execute, only after records are committed successfully to the database. then you can get record Id, and with the help of Id, you can update related object fields. if you want to update same object field, why don't you use before trigger? can you please elaborate requirement ?
I have a lead record which I send it across to another org through s2s. I am using the out-of-box s2s functionality and std 'Forward to connection' button for this. So after the record is end send across,I need to change the record owner to a queue.
I have written an after update trigger for the same. However I am unable to update the owner field
I am not sure,but if it's possible, do this way, whenever 'Forward to connection', button is clicked, execute apex code to change lead record owner to queue, before sending leads to another org. or if you can figure out order of execution using debug log, then it will be easy to implement this.
I am sorry for the troublw but I am new to salesforce. Where should I look for the action method. I found that the page is 'ForwardEntityPage'. However cannot find this page in the org.
In an after trigger, you have to create a new record since the record you are working with is 'read only'.
You can do this in your trigger as follows (snippet only to give you the idea -- not bulkified!)
for (Lead l : trigger.new) {
Lead lnew = new Lead(Id = l.Id, OwnerId = QueueYouWant);
update lnew;
}
All Answers
if you want to update same object field, why don't you use before trigger?
can you please elaborate requirement ?
Okay, I'll explain my requirement here.
I have a lead record which I send it across to another org through s2s. I am using the out-of-box s2s functionality and std 'Forward to connection' button for this. So after the record is end send across,I need to change the record owner to a queue.
I have written an after update trigger for the same. However I am unable to update the owner field
In an after trigger, you have to create a new record since the record you are working with is 'read only'.
You can do this in your trigger as follows (snippet only to give you the idea -- not bulkified!)
for (Lead l : trigger.new) {
Lead lnew = new Lead(Id = l.Id, OwnerId = QueueYouWant);
update lnew;
}
@parth
Can i do that without overriding the 'Forward to connection' button?
@JeffM
Can't do that. Its making my trigger run recursively.
You can always control the recursion. Here's a blurb on how that works: http://www.salesforce.com/docs/developer/cookbook/Content/apex_controlling_recursive_triggers.htm
I am sorry for the troublw but I am new to salesforce. Where should I look for the action method. I found that the page is 'ForwardEntityPage'. However cannot find this page in the org.