• Jared.Soell
  • NEWBIE
  • 5 Points
  • Member since 2016


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

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?