You need to sign in to do that
Don't have an account?
S_Batman
We have the following code to limit number of Protected Accounts to 1000 per user. I have one user that has 950 Protected Accounts and 50 unprotected Accounts. When I try to add another protected Account I am getting the error 'You already have 1000 Accounts in your ownership. Please remove one Account before adding a new.'.
I only want this error to occur when a user tries to add over 1000 Protected Accounts.
Is there something missing within the Apex?
Having Limited Protect Accounts per User
trigger Limit1000AccountsForUsers on Account (after insert, after update) {Account accs = Trigger.new[0]; string accountOwner = accs.OwnerId; If(accs.Protected_Accounts__c == true){Integer accounts = [ SELECT COUNT()FROM Account WHERE Account.OwnerId=: accountOwner]; system.debug(accounts); If(accounts > 2 ) {accs.addError('You already have 1000 Accounts in your ownership. Please remove one Account before adding a new.'); } } }
We have the following code to limit number of Protected Accounts to 1000 per user. I have one user that has 950 Protected Accounts and 50 unprotected Accounts. When I try to add another protected Account I am getting the error 'You already have 1000 Accounts in your ownership. Please remove one Account before adding a new.'.
I only want this error to occur when a user tries to add over 1000 Protected Accounts.
Is there something missing within the Apex?
Please see below change :
If(accs.Protected_Accounts__c == true){Integer accounts = [ SELECT COUNT()FROM Account WHERE Account.OwnerId=: accountOwner AND Protected_Accounts__c = True];