You need to sign in to do that
Don't have an account?
Ravindar Admin
Incompatible key type Account for Map<Id,Integer> at line 7 column 21
trigger CountCont on contact (after insert, after delete) {
map<Id, Integer> mapcount = new map<Id, Integer>();
if(trigger.isInsert) {
for(contact c : trigger.new) {
if(c.account != null) {
if(!mapcount.containsKey(c.account)) {
mapcount.put(c.account, 1);
} else {
mapcount.put(c.account, mapcount.get(c.account) + 1);
}
}
}
} else {
for(contact c : trigger.old) {
if(c.account != null) {
if(!mapcount.containsKey(c.account)) {
mapcount.put(c.account, -1);
} else {
mapcount.put(c.account, mapcount.get(c.account) - 1);
}
}
}
}
if(mapcount.size() > 0) {
List<account> a = [SELECT Id, size_of_account__c FROM account WHERE Id IN : mapcount.keySet()];
for(account ac : a) {
a.size_of_account__c += mapcount.get(a.Id);
}
update a;
}
}
map<Id, Integer> mapcount = new map<Id, Integer>();
if(trigger.isInsert) {
for(contact c : trigger.new) {
if(c.account != null) {
if(!mapcount.containsKey(c.account)) {
mapcount.put(c.account, 1);
} else {
mapcount.put(c.account, mapcount.get(c.account) + 1);
}
}
}
} else {
for(contact c : trigger.old) {
if(c.account != null) {
if(!mapcount.containsKey(c.account)) {
mapcount.put(c.account, -1);
} else {
mapcount.put(c.account, mapcount.get(c.account) - 1);
}
}
}
}
if(mapcount.size() > 0) {
List<account> a = [SELECT Id, size_of_account__c FROM account WHERE Id IN : mapcount.keySet()];
for(account ac : a) {
a.size_of_account__c += mapcount.get(a.Id);
}
update a;
}
}
please use this at line 7
mapcount.put(c.accountID, 1);
Let us know if this will help you