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

Trigger firing--help!
Hi,
I have a question in regards with when to fire a trigger.
Can i say on a Object , fire a trigger only when the Owner is "Some User".
I want to fire a trigger only when "user x" is the owner of the record.
Thanks in advance.
Sales4ce
Sure its possible. You just need to pick them out from the potential list of records that are batched as part of a trigger call.
example:
List<Account> listAccounts = new List<Accounts>();
for (Account acct : Trigger.new) {
if (acct.OwnerId == 'Some Owner Id') {
listAccounts.add(acct);
}
}
if (listAccounts.isEmpty() == false) {
//Process the list of accounts identified by owner
}
My suggestion would be to use CustomSettings to store the user id you want to check for rather than hardcoding the owner id in your code. Then you can modify the code to either process for a specific owner or multiple owner ids if you select a list type custom setting.
Hope this helps gets you started.
All Answers
Sure its possible. You just need to pick them out from the potential list of records that are batched as part of a trigger call.
example:
List<Account> listAccounts = new List<Accounts>();
for (Account acct : Trigger.new) {
if (acct.OwnerId == 'Some Owner Id') {
listAccounts.add(acct);
}
}
if (listAccounts.isEmpty() == false) {
//Process the list of accounts identified by owner
}
My suggestion would be to use CustomSettings to store the user id you want to check for rather than hardcoding the owner id in your code. Then you can modify the code to either process for a specific owner or multiple owner ids if you select a list type custom setting.
Hope this helps gets you started.
You can get owner id of that particular object as given in the example below :
Opportunity opp = [select owner.name,ownerid from opportunity where ownerid=:userinfo.getuserid()];
Hope this helps.