function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kevin TullosKevin Tullos 

Compile Error: Variable does not exist: Account.Owner... Please help

When we are updating the owner ID with out ERP system, we replicate the ownership change over to SFDC (it is called the salesman number) using informatica.  This - Salesman Number - field is on the user record and on the account record.  What I am trying to do is get a list of the account records where the Salesman number has been changed and update the owner of the account in salesforce with the owner that has the corresponding salesman number on the user record.  (does that make sense?)  Here is my code below, and I think that it is close, but I am getting the following complie error...

Error: Compile Error: Variable does not exist: Account.Owner at line 7 column 55

Here is the trigger I have written.  Please help.



trigger AccountOwnerUpdateTrigger on Account (before insert, before update) {

    // this map will contain a list of Accounts with the same salesman #
    Map<String, List<Account>> AccountOwnerMap = new Map<String, List<Account>> ();
    for( Account Acc : ) {
        // create the list if it doesn't already exist
        List<Account> AcctList = AccountOwnerMap.get( Account.Owner );
        if( AcctList == null ) {
            AcctList = new List<Account>();
        AcctList.add( Acc );
        AccountOwnerMap.put( Account.OwnerID, AcctList );

    // get list of CURRENTLY ACTIVE Sales Targets using the formula field Owner_Salesman_Number__c
    // and order it so that the latest sales target comes last
    List<User> UserList = [
                        SELECT ID, Salesman_Number__c
                        FROM User
                        WHERE ID IN :AccountByOwnerMap.keySet()
                        AND IsActive = TRUE

    // go through the Sales Target list and get a list of Sales Order that have the same salesman
    for( User User : UserList ) {
        List<Account> AcctList = AccountOwnerMap.get( User.ID );

        // assign the Sales Target for each Sales Order in the list
        // only if the Sales Target start date is before the Sales Order date
        // that is, if the Sales Target was active at the time of the order
        for( Account Acc : AcctList ) {
            Acc.User = Account.Ownerid;

Best Answer chosen by Kevin Tullos
Jim JamJim Jam
Actually, probably Acc.OwnerId.

All Answers


You just need to change line 7 to use Account.OwnerId, not Account.Owner:

List<Account> AcctList = AccountOwnerMap.get( Account.OwnerId );
Jim JamJim Jam
Actually, probably Acc.OwnerId.
This was selected as the best answer