You need to sign in to do that
Don't have an account?
The below Trigger is not working
Hello Masters,
My requirement here is to create a Trigger on Contact which, in case of change of record ownership, populates a field Previously Owned By with name of the previous owner of the record. Please find my code below and reflect some suggestions to make it work correctly.
trigger PreviousOwnerPopulate on Contact (before update)
{
Set <ID> PreviousId = new Set<ID>();
for (contact co: trigger.new)
{
for (Contact con: trigger.old)
{
if(co.OwnerID != con.OwnerID)
{
PreviousId.add(con.OwnerID);
}
}
}
map<id,string> mapforPreviousIdname = new map<id,string> ();
for (User u : [select id, name from User where id in:PreviousId])
{
mapforPreviousIdname.put(u.id,u.name);
}
for (contact c : trigger.new)
if (mapforPreviousIdname.size() > 0 )
{
c.Previously_Owned_By__c = mapforPreviousIdname.get(c.OwnerID);
}
}
You can use below code Please let me know if you face any issue.
If this solves your problem , please mark it as best answer/solved
All Answers
You can use below code Please let me know if you face any issue.
If this solves your problem , please mark it as best answer/solved