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

Can we have Triggers on fields rather than objects.
Hi,
I need to find out if the owner of account is changed during the batch processing.
Not sure if i can put a trigger on the field itself.
If i cannot the other option is to compare old and new values but i dont have a clue on how to do that.
Can somebody help ?
Thanks
Also this note taken from the documentation:
newMap:
A map of IDs to the new versions of the sObject records.
Note that this map is only available in before update, after insert, and after update
triggers.
oldMap:
A map of IDs to the old versions of the sObject records.
Note that this map is only available in update and delete triggers.
I tried something, gives no errors however the logic somehow does not work. What am I missing, please advice?
=================================================================================
trigger Update_OwnerNames on Account (after update) {
// MAP allows us to keep track of the accounts which have changed owner names.
Map<ID,Account> AccountwithChangedOwners = new Map<ID, Account> ();
for (Integer i=0; i<Trigger.new.size(); i++)
{
if( ( Trigger.old[i].Owner != Trigger.new[i].Owner)) // That means if the Owner name has been changed
{
AccountwithChangedOwners.put(Trigger.old[i].id, Trigger.new[i]);
}
}
List<Oppurtunity> UpdateOppurOwnername = new List<Oppurtunity>();
for (Oppurtunity opp: [SELECT ID, ACCOUNTID,Owner.Name FROM ACCOUNT WHERE ACCOUNTID IN :AccountwithChangedOwners.keySet()])
{
Account parentAccount = AccountwithChangedOwners.get(opp.ID);
opp.Owner = parentAccount.Owner; // This states that Oppurtunity Owner names should match the Account Owner name.
updatedOppurtunities.add(opp);
}
update updatedOppurtunites;
}
Message Edited by sumprit on 01-31-2008 04:59 PM