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
sales@myvarmasales@myvarma 

Illegal assignment from Map<Id,Account> to Map<Id,account>

User-added image



 
trigger updateact on Account(before update) {
 List<ID> accs=new List<ID>();
    Map<Id,Account> oldMap=Trigger.oldMap;
    Map<Id,Account> newMap=Trigger.NewMap;
   for(Id aid:oldMap.keySet())
   {
        if(oldMap.get(aid).AccountNumber!=newMap.get(aid).AccountNumberr)
        {
     accs.AccountNumber.addError(' Please contact Master Data to make this change.');
       }
    }
 
}

 
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi,

Please try with this code snippet,
 
trigger updateact on Account(before update) {
	for(Account acc : Trigger.New) {
		Account oldAccount = Trigger.oldMap.get(aid);
		if(oldAccount.AccountNumber != acc.AccountNumberr) {
			acc.addError(' Please contact Master Data to make this change.');
        }
	}
}

you don't have to create two other maps for this requirement. However, I would like to suggest you to used trigger handlers instead of writing the whole code into the trigger. Thats the best practise.

If this code solve your problem please make it as best answer. 

Thanks,
Prosenjit. 
sales@myvarmasales@myvarma
its still showing error
variable does not exist : AccountNumber   
Anurag SaxenaAnurag Saxena
Hi,
try this code
 
trigger updateact on Account(before update) 
{
Map<Id,Account> oldMap=Trigger.oldMap;
    
    for (Account acc : trigger.new)
    {
        Account oldAcc=trigger.oldMap.get(acc.id);
        	if (acc.accountnumber != oldAcc.accountnumber)
         	{
            	acc.adderror('Please contact Master Data to make this change.');
         	}
    }
 
}
surely it gonna help you 
Please choose as best answer :)

Thanks
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi , 

I had done a typo on this line oldAccount.AccountNumber != acc.AccountNumberr 

Please use this code, 
trigger updateact on Account(before update) {
	for(Account acc : Trigger.New) {
		Account oldAccount = Trigger.oldMap.get(aid);
		if(oldAccount.AccountNumber != acc.AccountNumber) {
			acc.addError(' Please contact Master Data to make this change.');
        }
	}
}

Thanks, 
Prosenjit
Amit Chaudhary 8Amit Chaudhary 8
Hi ,

Please check in your org you have any apex class with Account Name ? If yes then please rename that class or delete same class .

Please try to update your code like below
trigger updateact on Account(before update)
{
    for(Account acc : Trigger.New)
    {
        if( acc.AccountNumber  != Trigger.oldMap.get(acc.id).AccountNumber )
        {
			acc.AccountNumber.addError(' Please contact Master Data to make this change.');
		}
    }
}


Let us know if this will help you