You need to sign in to do that
Don't have an account?
shan876
List index out of bounds: 0 ?????
Hi all:
I do not know where am I going wrong but I keep getting errors rarely but do get errors on this trigger i wrote 3 times already...
Please let me know where am I going wrong...So far this is the new error:
Developer script exception from tsk : tsk: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0 Trigger.tsk: line 22, column 34
Thanks
I do not know where am I going wrong but I keep getting errors rarely but do get errors on this trigger i wrote 3 times already...
Code:
trigger tsk on Task (before insert,before update) { for(Task cs : trigger.new){ Account[] acc = [select Id, AccountNumber, Territory__c from Account where Id = :cs.WhatId]; Opportunity[] opp = [Select a.Id, a.AccountId From Opportunity a where Id=:cs.WhatId]; Case[] ca = [Select c.Id,c.AccountId from Case c where Id=:cs.WhatId]; if (acc.isEmpty()){ if(opp.isEmpty()) { Account actx = [Select Id, AccountNumber, Territory__c from Account where Id =:ca[0].AccountId]; cs.Dealer_ID__c = actx.AccountNumber; cs.Territory__c = actx.Territory__c; } if(ca.isEmpty()) { Account act = [Select Id, AccountNumber, Territory__c from Account where Id = :opp[0].AccountId]; cs.Dealer_ID__c = act.AccountNumber; cs.Territory__c = act.Territory__c; } } else if(cs.WhatId != null) { cs.Dealer_ID__c = acc[0].AccountNumber; cs.Territory__c = acc[0].Territory__c; } } }
Please let me know where am I going wrong...So far this is the new error:
Developer script exception from tsk : tsk: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0 Trigger.tsk: line 22, column 34
Thanks
But the task was created off the case??
How can I fix it?
It would cause that error if cs.whatId is null
Message Edited by Luke@TWS on 10-15-2008 07:37 AM