You need to sign in to do that
Don't have an account?
Incompatible key type String for MAP<Integer,Account> at line 9 column 16
HI,
I am trying to perform duplicate check for phone number field in account but i am getting following error..
trigger Duplicatecheck on Account (before insert,before update)
{
map<integer,Account> getphone=new map<integer,Account>();
for(Account acc:trigger.new)
{
if(acc.Phone!=null &&(trigger.isinsert || acc.Phone!=trigger.oldmap.get(acc.id).Phone))
{
if(getphone.containskey(acc.Phone))//error:Incompatible key type String for MAP<Integer,Account>
{
acc.Phone.adderror('A New Lead As Same Email');
}
}
else
{
getphone.get(acc.Phone);
}
}
for(account accc:[select Phone from account where Phone in:getphone.keyset()])
{
account newaccount=getphone.get(accc.Phone);
newaccount.Phone.adderror('Lead Exits With Same email');
}
}
You map is MAP<Integer,Account> thats means your key must be of integer type. Where account.phone is not a numeric/integer field. Its a string type field. So you cannot use this field to check map.
If you want to make account.phone as a key then you have to create map like Map<String, Account>.