function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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){
        tsIds.add(ts.WhoId);
     }
     
     
     Map<ID, Task> mapAccounts = new Map<ID, Task>([SELECT Id, F1__c from Task where Id IN :tsIds]);
     
     
     if(Trigger.isUpdate){

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.
Please 
tell me what changes need to be don.

Thanks in Advance
V V Satyanarayana MaddipatiV V Satyanarayana Maddipati
Hi,

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?