• -d-g-
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 8
    Replies

So, I've got a couple of triggers that work well when working directly from tasks or events.  An issue has arisen though, where the triggers are causing this: System.ListException: List index out of bounds: 0 when someone tries to Convert a Lead.  Here is the offending code:

 

Id WhoIDCheck = trigger.new[0].WhoId;

List<Event> WhoNum = [SELECT Who.Type FROM Task WHERE WhoId = :WhoIDCheck];

 

The trigger is a Before Update trigger, I am thinking about converting the trigger to an After Update, but I really don't understand how the whole process of converting a lead works (what happens to the ID over the course of the process, it seems to be changed, but when?), so I don't know if that will work.  Any suggestions/help would be greatly appreciated.

So, I am getting this:

Error: Invalid Data.
TasksOutlookTaskUpdate: execution of BeforeInsert caused by: System.ListException: List index out of bounds: 0: Trigger.TasksOutlookTaskUpdate: line 7, column 1 ...

... when I try to use certain accounts/contacts/opportunities.  It seems like accounts/contacts/opportunities created before a certain hour today, show up in the query making the trigger function; but after a certain time today, there is nothing but failure.  I've tried to mess around with it, but have come up with nothing ... any help would be appreciated!

Here's the code:

trigger TasksOutlookTaskUpdate on Task (before insert, before update) {
    String TaskType = trigger.new[0].Type;
    Id WhoIDCheck = trigger.new[0].WhoId;
    Id WhatIDCheck = trigger.new[0].WhatId;
    List<Task> RefName = [SELECT What.Type, What.Name FROM Task WHERE WhatId = :WhatIDCheck];
    List<Task> WhoNum = [SELECT Who.Type FROM Task WHERE WhoId = :WhoIDCheck];
    If ( WhoNum[0].Who.Type == 'Contact' ) {
        List<Contact> ContData = [SELECT Name, Phone, Email FROM Contact WHERE Id = :WhoIDCheck];
        String TaskID = trigger.new[0].Id;
        string ForOutlook = 'Type: ' + TaskType + '\n' + 'Related To: ' + RefName[0].What.Type + ': '
        + RefName[0].What.Name + '\n'
        + 'Contact: ' + ContData[0].Name + '\n' + 'Phone: ' + ContData[0].Phone + '\n' + 'Email: ' + ContData[0].Email + '\n';
        // + 'Link to Activity: https://na6.salesforce.com/' + TaskID
        trigger.new[0].TMP_Outlook_Reference__c = ForOutlook;
    } else if ( WhoNum[0].Who.Type == 'Lead' ) {
        List<Lead> LeadData = [SELECT Name, Phone, Email FROM Lead WHERE Id = :WhoIDCheck];
        String TaskID = trigger.new[0].Id;
        string ForOutlook = 'Type: ' + TaskType + '\n' + 'Related To: ' + RefName[0].What.Type + ': '
        + RefName[0].What.Name + '\n'
        + 'Contact: ' + LeadData[0].Name + '\n' + 'Phone: ' + LeadData[0].Phone + '\n' + 'Email: ' + LeadData[0].Email + '\n';
        // + 'Link to Activity: https://na6.salesforce.com/' + TaskID;
        trigger.new[0].TMP_Outlook_Reference__c = ForOutlook;
    }
}

thanks!

I am getting an exception because one of my queries is not returning results, I'm not sure why, can you take a look?

This is the line that's causing the problem: List<Quote> Synced = [SELECT Synced_Quote_Id__c FROM Quote WHERE Id = :quotelid[0].Id];

 

Here's the rest of the code, if that helps.  Thanks!

 

trigger SyncdQuoteUpdate onMilestone1_Project__c (beforeinsert, beforeupdate) {

Id INVLI = trigger.new[0].Invoice_Line_Item__c;

String SyncedQuote = trigger.new[0].Synced_Quote__c;

Date breakdate = Date.newinstance(2012, 7, 8);

Date CreationDate = trigger.new[0].Created_Date__c;

System.Debug(INVLI);

List<QuoteLineItem> quotelid = [SELECT QuoteId FROM QuoteLineItem WHERE Id = :INVLI];

List<Quote> Synced = [SELECT Synced_Quote_Id__c FROM Quote WHERE Id = :quotelid[0].Id];

if ( CreationDate > breakdate ) {

if (SyncedQuote == null) {

trigger.new[0].Synced_Quote__c = Synced[0].Id;

}

}

}