You need to sign in to do that
Don't have an account?
Mark R Keyworth
Update custom relationship based on a standard relationship.
Hello there!
Let me preface this by saying that custom coding is well outside of my wheelhouse. That said, I am trying to update the value of a custom relationship field on Leads when the owner of the Lead is changed. My code is not throwing any errors, but it is also not updating the custom relationship as I would expect. I have no idea what I am doing wrong. The code is as follows:
Let me preface this by saying that custom coding is well outside of my wheelhouse. That said, I am trying to update the value of a custom relationship field on Leads when the owner of the Lead is changed. My code is not throwing any errors, but it is also not updating the custom relationship as I would expect. I have no idea what I am doing wrong. The code is as follows:
trigger leadAutoSAChangeTEST on Lead (after update) { for( Id leadId : Trigger.newMap.keySet() ) { if( Trigger.oldMap.get(leadId).Owner != Trigger.newMap.get(leadId).Owner ) { Lead leadtoUpdate = Trigger.newMap.get(leadId); leadtoUpdate.Sales_Agent__c = [SELECT Id FROM Sales_Agent__c WHERE Name = :Trigger.newMap.get(leadId).Owner.Name LIMIT 1].Id; update leadtoUpdate; } } }
In this case, I think you should be use "before update". Because, on the "after update" you cannot update the current record.
Hope that can help you.