• Sree_salesforce
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hi All,

 

Trigger On Task

 

trigger AddTaskActivityToAccountTLA on Task (after insert) {
for (Task task: Trigger.new){
if(task.WhatId!=null){
List<Account> accounts = [select id from Account];
system.debug('Size------------>'+accounts.size());
//List<Account> accounts = [select Name from Account where id =: task.WhatId];
//system.debug('Size------------>'+accounts.size());
if(accounts.size() > 0){
system.debug('accounts[0].id------->'+accounts[0].id);
AccountTLA__c[] accountTLA = [select id from AccountTLA__c where Account__c=: accounts[0].id];
system.debug('accountTLA.size()------->'+accountTLA.size());
if(accountTLA.size()>0){
system.debug('account[0].id------->'+accountTLA[0].id);
Task newtask= new Task(Type=task.Type,OwnerId=task.OwnerId,Subject=task.Subject,ActivityDate=task.ActivityDate,Status=task.Status,Priority=task.Priority,WhatId=accountTLA[0].id);
insert newtask;

}
}
}
}
}

 

I am not able to get account records in the trigger.where i am going wrong....

 

Best ,

Sree

 

 

 

Hi All,

 

Trigger On Task

 

trigger AddTaskActivityToAccountTLA on Task (after insert) {
for (Task task: Trigger.new){
if(task.WhatId!=null){
List<Account> accounts = [select id from Account];
system.debug('Size------------>'+accounts.size());
//List<Account> accounts = [select Name from Account where id =: task.WhatId];
//system.debug('Size------------>'+accounts.size());
if(accounts.size() > 0){
system.debug('accounts[0].id------->'+accounts[0].id);
AccountTLA__c[] accountTLA = [select id from AccountTLA__c where Account__c=: accounts[0].id];
system.debug('accountTLA.size()------->'+accountTLA.size());
if(accountTLA.size()>0){
system.debug('account[0].id------->'+accountTLA[0].id);
Task newtask= new Task(Type=task.Type,OwnerId=task.OwnerId,Subject=task.Subject,ActivityDate=task.ActivityDate,Status=task.Status,Priority=task.Priority,WhatId=accountTLA[0].id);
insert newtask;

}
}
}
}
}

 

I am not able to get account records in the trigger.where i am going wrong....

 

Best ,

Sree