My trigger
trigger testtrigger on Contact (after insert,after delete,after undelete){
id accountId;
id accountsid;
for(Contact c:trigger.new){
accountId=c.AccountId;
}
Integer count=[select count() from contact where AccountId=:accountId];
if(trigger.isAfter && trigger.isInsert){
for(Account a:[select number_of_contacts__c from Account where id=:accountId]){
count=count+1;
a.number_of_contacts__c=count;
update a;
}
}
if(trigger.isDelete){
for(Contact c:trigger.old){
accountsId=c.AccountId;
}
for(Account a:[select number_of_contacts__c from Account where id=:accountsId]){
count=count-1;
a.number_of_contacts__c=count;
update a;
}
}
if(trigger.isAfter && trigger.isUndelete){
for(Account a:[select number_of_contacts__c from Account where id=:accountId]){
count=count+1;
a.number_of_contacts__c=count;
update a;
}
}
}
Error
Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger testtrigger caused an unexpected exception, contact your administrator: testtrigger: execution of AfterDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.testtrigger: line 5, column 1".
i am not able to delete contacts