+ Start a Discussion
SFDC Coder 8SFDC Coder 8 

Trigger to update from Task to Contact

Hi All,
I have written a Trigger to update from Task to Contact,

This is my trigger
trigger updateTask on Task (after update) {
List<Id> tsIds = new List<Id>();

for(Task ts : trigger.new){
     Map<ID, Task> mapAccounts = new Map<ID, Task>([SELECT Id, F1__c from Task where Id IN :tsIds]);

List<Contact>  lstCon = [SELECT Id, name, CF1__c,AccountId FROM Contact where AccountId IN :tsIds];

For(Contact con : lstCon)
     Task ts = mapAccounts.get(con.AccountId);
          con.CF1__c= ts.F1__c;
update lstCon;

When I am updating Task record I am getting System.NullPointerException: Attempt to de-reference a null object:​ error.
tell me what changes need to be don.

Thanks in Advance
V V Satyanarayana MaddipatiV V Satyanarayana Maddipati

From line no: 18 you are getting the Null Pointer Exception.  And your code is written wrong.
1). Whoid contains only lead and ContactId.
SFDC Coder 8SFDC Coder 8
Hi satyanarayana
Can you please suggest me what changes need to be done?