• AwkwardA
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 9
    Replies
I've created the following trigger and it is only updating the task before an update and not before an insert. Help me troubleshoot?

trigger EmailISResponse on Task (before insert, before update) {

List<User> InsideSalesUser = [SELECT Id FROM User where UserRoleId='00E30000001rctV'];

Set<Id> InsideSalesUserId = new set<Id>();
if (InsideSalesUser != NULL){

for (User u :InsideSalesUser) {
    InsideSalesUserId.add(u.Id);
    }
}

List<Lead> LeadsWithCampaign = [SELECT Id FROM Lead where Current_Teleprospecting_Campaign__c != NULL];
Set<Id> LeadsWithCampaignId = new set<Id>();
if (LeadsWithCampaign != NULL){

for (Lead l :LeadsWithCampaign) {
    LeadsWithCampaignId.add(l.id);
    }
}

for (Task t: Trigger.new) {
    if(InsideSalesUserId.contains(t.OwnerID) && t.WhoId != NULL && LeadsWithCampaignId.contains(t.WhoId) && t.IsClosed == true && String.valueOf(t.WhoId).startsWith('00Q')&& t.Subject != NULL && String.valueOf(t.Subject).startsWith('Email'))
    
    t.IS_Response__c = true;
    }
}


I'm getting the "Too many SOQL queries" error on Line 17. Help me troubleshoot?

trigger InsideSalesAppointment on Task (after insert, after update) {

Map<Id,Date> LeadsToUpdate = new Map<Id,Date>();
List<User> InsideSalesUser = [SELECT Id FROM User where UserRoleId='00E30000001rctV'];
Set<Id> InsideSalesUserId = new set<Id>();
for (User u :InsideSalesUser) {
    InsideSalesUserId.add(u.Id);
    }


for (Task t: Trigger.new) {
    if(InsideSalesUserId.contains(t.OwnerID) && t.IsClosed == false && String.valueOf(t.WhoId).startsWith('00Q') && t.WhoId != NULL)
    
    LeadsToUpdate.put(t.WhoId, t.ActivityDate);
    }

List<Lead> LeadsAppointment = [SELECT Id FROM Lead where Id IN:LeadsToUpdate.keyset()];

if (LeadsToUpdate.keyset().size()>0){

for (Lead l: LeadsAppointment) {

    l.Next_Appointment_Date__c = LeadsToUpdate.get(l.id);
    }
    update LeadsAppointment;
}
}


Every now and then I get a ___ error on this trigger (on Line #7):

trigger HandoffToISRLead on Task (after insert) {

Map<Id,Id> LeadsToUpdate = new Map<Id,Id>();


for (Task t: Trigger.new) {
    if(t.Subject.startsWith('Handoff to ISR') && t.WhoId != NULL && String.valueOf(t.WhoId).startsWith('00Q'))
    
    LeadsToUpdate.put(t.WhoId, NULL);
    }

List<Lead> LeadsToHandoff = [SELECT Id, Last_ISR_ID__c, ISR_Handoff_Counter__c, LeadSource FROM Lead where Id IN:LeadsToUpdate.keyset()];

if (LeadsToUpdate.keyset().size()>0){

for (Lead l: LeadsToHandoff) {
    l.SD_Pipeline__c = true;
    if(l.ISR_Handoff_Counter__c != NULL){
    l.ISR_Handoff_Counter__c = l.ISR_Handoff_Counter__c + 1;}
    else{l.ISR_Handoff_Counter__c = 1;}

    if(l.Last_ISR_ID__c != NULL){
    l.OwnerID = l.Last_ISR_ID__c;
    }
    else if(l.LeadSource == 'Partner/Vendor'){l.OwnerID = '00530000009b58p';}
    else{l.OwnerID = '00530000009sb4g';
}
    }
    update LeadsToHandoff;
}
}

Here is some of the recent debug code:

16:16:53.139 (139810822)|CODE_UNIT_STARTED|[EXTERNAL]|01q30000000a8Hi|HandoffToISRLead on Task trigger event AfterInsert for [00T3000002gcWfr, 00T3000002gcWfs]
16:16:53.139 (139836969)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
16:16:53.139 (139876331)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
16:16:53.139 (139893603)|VARIABLE_SCOPE_BEGIN|[1]|this|HandoffToISRLead|true|false
16:16:53.139 (139954648)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x7e3d9e08
16:16:53.139 (139977350)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
16:16:53.139 (139987725)|VARIABLE_SCOPE_BEGIN|[1]|this|HandoffToISRLead|true|false
16:16:53.140 (140005443)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x7e3d9e08
16:16:53.140 (140012249)|STATEMENT_EXECUTE|[1]
16:16:53.140 (140015277)|STATEMENT_EXECUTE|[3]
16:16:53.140 (140025872)|HEAP_ALLOCATE|[3]|Bytes:4
16:16:53.140 (140061801)|VARIABLE_ASSIGNMENT|[3]|this.LeadsToUpdate|{"serId":1,"value":{}}|0x7e3d9e08
16:16:53.140 (140138730)|HEAP_ALLOCATE|[6]|Bytes:5
16:16:53.140 (140167629)|VARIABLE_SCOPE_BEGIN|[6]|t|Task|true|false
16:16:53.140 (140589412)|VARIABLE_ASSIGNMENT|[6]|t|{"RecordTypeId":"01230000001dnNMAAY","Event_Completed__c":false,"CurrencyIsoCode":"USD","LastModifiedById":"00530000009beV7AAI","OwnerId":"00530000009beV7AAI","LastModifiedDate":"2014-05-14T23:16:53.000Z","ActivityDate":"2014-05-14T00:00:00.000Z","IsRecurrence":false,"Priority":"Normal","IsArchived":false,"Status":"Not Started","IsClosed":false,"IsVisibleInSelfServi (2 more) ...":false,"qbdialer__SMSReminde (4 more) ...":false,"DB_Activity_Type__c":"Other","IsReminderSet":false,"SystemModstamp":"2014-05-14T23:16:53.000Z","CreatedById":"00530000009beV7AAI","CreatedDate":"2014-05-14T23:16:53.000Z","IsDeleted":false,"Id":"00T3000002gcWfrEAE","IS_Response__c":false}|0x589b05d7
16:16:53.140 (140602741)|STATEMENT_EXECUTE|[6]
16:16:53.140 (140623278)|HEAP_ALLOCATE|[7]|Bytes:14
16:16:53.140 (140738987)|HEAP_ALLOCATE|[7]|Bytes:41
16:16:53.140 (140899452)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Trigger.HandoffToISRLead: line 7, column 1
16:16:53.140 (140913883)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Trigger.HandoffToISRLead: line 7, column 1
16:16:53.140 (140989867)|CODE_UNIT_FINISHED|HandoffToISRLead on Task trigger event AfterInsert for [00T3000002gcWfr, 00T3000002gcWfs]
16:16:53.140 (140997965)|EXECUTION_FINISHED


I tried looking for the 2 tasks in the debug code, but received this error when trying to access them:

Data Not Available
The data you were trying to access could not be found. It may be due to another user deleting the data or a system error. If you know the data is not deleted but cannot access it, please look at our support page.

 

What's the best way to fix this? Feel like I'm missing something simple.

I've created the following trigger and it is only updating the task before an update and not before an insert. Help me troubleshoot?

trigger EmailISResponse on Task (before insert, before update) {

List<User> InsideSalesUser = [SELECT Id FROM User where UserRoleId='00E30000001rctV'];

Set<Id> InsideSalesUserId = new set<Id>();
if (InsideSalesUser != NULL){

for (User u :InsideSalesUser) {
    InsideSalesUserId.add(u.Id);
    }
}

List<Lead> LeadsWithCampaign = [SELECT Id FROM Lead where Current_Teleprospecting_Campaign__c != NULL];
Set<Id> LeadsWithCampaignId = new set<Id>();
if (LeadsWithCampaign != NULL){

for (Lead l :LeadsWithCampaign) {
    LeadsWithCampaignId.add(l.id);
    }
}

for (Task t: Trigger.new) {
    if(InsideSalesUserId.contains(t.OwnerID) && t.WhoId != NULL && LeadsWithCampaignId.contains(t.WhoId) && t.IsClosed == true && String.valueOf(t.WhoId).startsWith('00Q')&& t.Subject != NULL && String.valueOf(t.Subject).startsWith('Email'))
    
    t.IS_Response__c = true;
    }
}


I'm getting the "Too many SOQL queries" error on Line 17. Help me troubleshoot?

trigger InsideSalesAppointment on Task (after insert, after update) {

Map<Id,Date> LeadsToUpdate = new Map<Id,Date>();
List<User> InsideSalesUser = [SELECT Id FROM User where UserRoleId='00E30000001rctV'];
Set<Id> InsideSalesUserId = new set<Id>();
for (User u :InsideSalesUser) {
    InsideSalesUserId.add(u.Id);
    }


for (Task t: Trigger.new) {
    if(InsideSalesUserId.contains(t.OwnerID) && t.IsClosed == false && String.valueOf(t.WhoId).startsWith('00Q') && t.WhoId != NULL)
    
    LeadsToUpdate.put(t.WhoId, t.ActivityDate);
    }

List<Lead> LeadsAppointment = [SELECT Id FROM Lead where Id IN:LeadsToUpdate.keyset()];

if (LeadsToUpdate.keyset().size()>0){

for (Lead l: LeadsAppointment) {

    l.Next_Appointment_Date__c = LeadsToUpdate.get(l.id);
    }
    update LeadsAppointment;
}
}


Every now and then I get a ___ error on this trigger (on Line #7):

trigger HandoffToISRLead on Task (after insert) {

Map<Id,Id> LeadsToUpdate = new Map<Id,Id>();


for (Task t: Trigger.new) {
    if(t.Subject.startsWith('Handoff to ISR') && t.WhoId != NULL && String.valueOf(t.WhoId).startsWith('00Q'))
    
    LeadsToUpdate.put(t.WhoId, NULL);
    }

List<Lead> LeadsToHandoff = [SELECT Id, Last_ISR_ID__c, ISR_Handoff_Counter__c, LeadSource FROM Lead where Id IN:LeadsToUpdate.keyset()];

if (LeadsToUpdate.keyset().size()>0){

for (Lead l: LeadsToHandoff) {
    l.SD_Pipeline__c = true;
    if(l.ISR_Handoff_Counter__c != NULL){
    l.ISR_Handoff_Counter__c = l.ISR_Handoff_Counter__c + 1;}
    else{l.ISR_Handoff_Counter__c = 1;}

    if(l.Last_ISR_ID__c != NULL){
    l.OwnerID = l.Last_ISR_ID__c;
    }
    else if(l.LeadSource == 'Partner/Vendor'){l.OwnerID = '00530000009b58p';}
    else{l.OwnerID = '00530000009sb4g';
}
    }
    update LeadsToHandoff;
}
}

Here is some of the recent debug code:

16:16:53.139 (139810822)|CODE_UNIT_STARTED|[EXTERNAL]|01q30000000a8Hi|HandoffToISRLead on Task trigger event AfterInsert for [00T3000002gcWfr, 00T3000002gcWfs]
16:16:53.139 (139836969)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
16:16:53.139 (139876331)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
16:16:53.139 (139893603)|VARIABLE_SCOPE_BEGIN|[1]|this|HandoffToISRLead|true|false
16:16:53.139 (139954648)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x7e3d9e08
16:16:53.139 (139977350)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
16:16:53.139 (139987725)|VARIABLE_SCOPE_BEGIN|[1]|this|HandoffToISRLead|true|false
16:16:53.140 (140005443)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x7e3d9e08
16:16:53.140 (140012249)|STATEMENT_EXECUTE|[1]
16:16:53.140 (140015277)|STATEMENT_EXECUTE|[3]
16:16:53.140 (140025872)|HEAP_ALLOCATE|[3]|Bytes:4
16:16:53.140 (140061801)|VARIABLE_ASSIGNMENT|[3]|this.LeadsToUpdate|{"serId":1,"value":{}}|0x7e3d9e08
16:16:53.140 (140138730)|HEAP_ALLOCATE|[6]|Bytes:5
16:16:53.140 (140167629)|VARIABLE_SCOPE_BEGIN|[6]|t|Task|true|false
16:16:53.140 (140589412)|VARIABLE_ASSIGNMENT|[6]|t|{"RecordTypeId":"01230000001dnNMAAY","Event_Completed__c":false,"CurrencyIsoCode":"USD","LastModifiedById":"00530000009beV7AAI","OwnerId":"00530000009beV7AAI","LastModifiedDate":"2014-05-14T23:16:53.000Z","ActivityDate":"2014-05-14T00:00:00.000Z","IsRecurrence":false,"Priority":"Normal","IsArchived":false,"Status":"Not Started","IsClosed":false,"IsVisibleInSelfServi (2 more) ...":false,"qbdialer__SMSReminde (4 more) ...":false,"DB_Activity_Type__c":"Other","IsReminderSet":false,"SystemModstamp":"2014-05-14T23:16:53.000Z","CreatedById":"00530000009beV7AAI","CreatedDate":"2014-05-14T23:16:53.000Z","IsDeleted":false,"Id":"00T3000002gcWfrEAE","IS_Response__c":false}|0x589b05d7
16:16:53.140 (140602741)|STATEMENT_EXECUTE|[6]
16:16:53.140 (140623278)|HEAP_ALLOCATE|[7]|Bytes:14
16:16:53.140 (140738987)|HEAP_ALLOCATE|[7]|Bytes:41
16:16:53.140 (140899452)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Trigger.HandoffToISRLead: line 7, column 1
16:16:53.140 (140913883)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Trigger.HandoffToISRLead: line 7, column 1
16:16:53.140 (140989867)|CODE_UNIT_FINISHED|HandoffToISRLead on Task trigger event AfterInsert for [00T3000002gcWfr, 00T3000002gcWfs]
16:16:53.140 (140997965)|EXECUTION_FINISHED


I tried looking for the 2 tasks in the debug code, but received this error when trying to access them:

Data Not Available
The data you were trying to access could not be found. It may be due to another user deleting the data or a system error. If you know the data is not deleted but cannot access it, please look at our support page.

 

What's the best way to fix this? Feel like I'm missing something simple.