You need to sign in to do that
Don't have an account?
S_Batman
But I noticed it only goes by the logged in user. Is there a way to update the trigger so it limits the Protected Accounts regardless of the user?
Limit Number of Accounts Per User
I am trying to Limit the number of Protected Accounts a User should have under their ownership. This is the trigger I created with the help of the SFDC Community
trigger Limit1000AccountsForUsers on Account (before insert, before update) { Account accs = Trigger.new[0]; if (accs.Protected_Accounts__c == true) { Integer accounts = [ SELECT COUNT()FROM Account WHERE Account.OwnerId = : userInfo.getUserId()]; system.debug(accounts); if (accounts >3 ) { accs.addError('You are your limit of Accounts.'); } } }
But I noticed it only goes by the logged in user. Is there a way to update the trigger so it limits the Protected Accounts regardless of the user?
You can change your query to look at the owner of the account that fired the trigger instead. This is what your query would look like:
Please choose as best answer if this helped!
All Answers
You can change your query to look at the owner of the account that fired the trigger instead. This is what your query would look like:
Please choose as best answer if this helped!
Thanks