• ManishKlkrn
  • NEWBIE
  • 95 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I have a trigger on TASK and handler class which is on After Insert and After Update, updates custom fields on account.

for Task - contact (whoId) is required field.
when a user logs a call from contact, he may not enter the WhatID(Account). So i'm trying to query and get the WhatId from WhoId of a task adn also trying to Bulkify Code.

HandlerClass:

 public void updateAccountActivityFields(Task[] taskRecords){
 Set<String> conIDs = new Set<String>();
 for(Task t : taskRecords){
            conIDs.add(t.WhoID);
        } 
//query outside forloop
//Account and contact have lookup relationship
 List<Contact> accIDs = [SELECT AccountId FROM Contact WHERE Id IN :conIDs];

//getting ERROR at this line 
List<Account> accountsToUpdate = [SELECT Id FROM Account WHERE Id IN :accIDs];

 for(Task t: [SELECT Id, LastModifiedBy.name, type, LastModifiedDate, CreatedDate, RecordTypeId, WhoID, WhatID FROM task WHERE id in :taskRecords]){
for(Account a : accountsToUpdate){
//Logic here
}
}
}

 
I have a trigger on TASK and handler class which is on After Insert and After Update, updates custom fields on account.

for Task - contact (whoId) is required field.
when a user logs a call from contact, he may not enter the WhatID(Account). So i'm trying to query and get the WhatId from WhoId of a task adn also trying to Bulkify Code.

HandlerClass:

 public void updateAccountActivityFields(Task[] taskRecords){
 Set<String> conIDs = new Set<String>();
 for(Task t : taskRecords){
            conIDs.add(t.WhoID);
        } 
//query outside forloop
//Account and contact have lookup relationship
 List<Contact> accIDs = [SELECT AccountId FROM Contact WHERE Id IN :conIDs];

//getting ERROR at this line 
List<Account> accountsToUpdate = [SELECT Id FROM Account WHERE Id IN :accIDs];

 for(Task t: [SELECT Id, LastModifiedBy.name, type, LastModifiedDate, CreatedDate, RecordTypeId, WhoID, WhatID FROM task WHERE id in :taskRecords]){
for(Account a : accountsToUpdate){
//Logic here
}
}
}