I have written a trigger to update one custom field on activity which is a lookup to account.
I have to update that field with the account for account and one custom object (property relation)
When i just run a trigger for Account , it works .But when i have written the whole trigger, Its not updating the activity field for account .The trigger is working fine for Property relation object.
This is my trigger
trigger populateAccount on Task (before insert,before update) {
List<Id> AccountIds = new List<Id>();
String strTempId;
if(trigger.isInsert || trigger.isUpdate){
for(Task t : trigger.new){
strTempId = string.valueOf(t.WhatId);
System.debug('++++++++Test strTempId+++++++++++:'+strTempId.startsWith('001'));
if(strTempId != null && strTempId.startsWith('001')){
System.debug('++++++++InIF+++++++++++');
t.Account__C = t.WhatId;
}
else if(strTempId.startsWith('a0p')){
AccountIds.add(t.WhatId);
}
}
map<id,id> mapAccounts = new map<Id,id>();
if(AccountIds.size() > 0 && AccountIds!= null){
for(Property_Relation__c objPropertyRelation:[select id,Account__c from Property_Relation__c where id in:AccountIds]){
mapAccounts.put(objPropertyRelation.id,objPropertyRelation.Account__c);
}
}
for(Task t : trigger.new){
t.Account__c = mapAccounts.get(t.whatId);
}
}
}