• Andrew Dahlkemper 12
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi all,

I've search around a ton and can't find an example trigger to do the following: I'd like to fill in a custom field (lookup user) on the Task object for who the Account owner is whenever a Task is created.

My use case is I just want a way to identify who is creating Tasks on Accounts that are not owned by them (bad sales rep! bad!).

My custom field on Tasks is called Account_Owner__c. I already have an Apex Class that I believe will work. Any suggestions?  Thank you!
I am trying to create a Trigger to limit the number of Account a User can own.
Here is my code:
trigger Accounts75Limit on Account (after insert, after update) {

    //List<Account> acc = new List<Account>();
	for(Account acc : trigger.new)
    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 >3 ) {
            accs.addError('You are your limit of Accounts.');
        }
    }
}

I am getting the following errors:
User-added image

Any ideas?

Thanks!
I am trying to create a Trigger to limit the number of Account a User can own.
Here is my code:
trigger Accounts75Limit on Account (after insert, after update) {

    //List<Account> acc = new List<Account>();
	for(Account acc : trigger.new)
    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 >3 ) {
            accs.addError('You are your limit of Accounts.');
        }
    }
}

I am getting the following errors:
User-added image

Any ideas?

Thanks!