+ Start a Discussion
Jin D.ax1084Jin D.ax1084 

Attempt to de-reference a null object

I'm getting an error message periodically: attempt to de-reference a null object on line 79 column 13.  Can someone tell me what's wrong?

 

  • trigger leadRoundRobin on Lead (before insert, before update) {
        //
        //Check if assignment owner has changed
        //
        Map<Integer,Id> queueIds = new Map<Integer,Id>();   //Trigger index --> Queue ID
        
        Integer idx = 0;
        for (Lead cs : Trigger.new)
        {
            if(Trigger.isUpdate) {  
                if(cs.OwnerId <> Trigger.oldMap.get(cs.id).OwnerId) {
                    if (cs.TempOwnerId__c == 'SKIP') {
                        Trigger.new[idx].TempOwnerId__c = '';
                    } else {
                        queueIds.put(idx, cs.OwnerId);
                    }
                }           
            }else {
                queueIds.put(idx, cs.OwnerId);
            }   
            idx++;
        }
        System.debug('>>>>>queueIds: '+queueIds);
        if (queueIds.isEmpty()) return;
        
        //
        //Find active Assignment Group for Queue
        //
        Map<Integer,Id> asgnGroupNameIds = new Map<Integer,Id>();   //Trigger index --> Assignment_Group_Name ID
        Map<Id,Assignment_Group_Queues__c> asgnGroupQueues = new Map<Id,Assignment_Group_Queues__c>(); //Queue ID --> Assignment Group Queues
        
        for(Assignment_Group_Queues__c[] agq : [SELECT Assignment_Group_Name__c, QueueId__c
                                              FROM Assignment_Group_Queues__c 
                                              WHERE QueueId__c in :queueIds.values()
                                              AND Active__c = 'True'])
        {
            for (Integer i = 0; i < agq.size() ; i++) {
                asgnGroupQueues.put(agq[i].QueueId__c, agq[i]);
            }                                           
        }
        System.debug('>>>>>asgnGroupQueues: '+asgnGroupQueues); 
        if (asgnGroupQueues.isEmpty()) return;
    
        for (Integer i : queueIds.keySet()) {
            Assignment_Group_Queues__c agq = asgnGroupQueues.get(queueIds.get(i));
            
            if (agq <> null) {
                asgnGroupNameIds.put(i, agq.Assignment_Group_Name__c);
            }
            //else no active assignment group queue error
        }
        System.debug('>>>>>asgnGroupNameIds: '+asgnGroupNameIds);
        if (asgnGroupNameIds.isEmpty()) return;
        
        //
        //Determine next valid user in Queue/Assignment Group for round robin
        //User with earliest last assignment date wins.
        //
        Map<Id,Assignment_Groups__c[]> asgnGroups = new Map<Id,Assignment_Groups__c[]>(); // Assignment Group Name ID --> User ID
        for(Assignment_Groups__c[] ags : [SELECT Group_Name__c, User__c, Last_Assignment__c, Millisecond__c 
                                       FROM Assignment_Groups__c 
                                       WHERE Group_Name__c in :asgnGroupNameIds.values() 
                                       AND Active__c = 'True' AND User_Active__c = 'True'
                                       ORDER BY Last_Assignment__c, Millisecond__c])
        {
            if (ags.size()>0) {
                asgnGroups.put(ags[0].Group_Name__c, ags);
            }
        }
        System.debug('>>>>>asgnGroups: '+asgnGroups);   
        if (asgnGroups.isEmpty()) return;
    
        Map<Id,Assignment_Groups__c> updateAssignmentGroups = new Map<Id,Assignment_Groups__c>();
        Map<Id, datetime> latestAGDateTime = new Map<Id,datetime>();
        idx = 0;    
        for (Integer i : queueIds.keySet())
        {
            Assignment_Groups__c[] ags = asgnGroups.get(asgnGroupNameIds.get(i));
     if (ags.size()>0)
            {   
                //Choose next user in line if user ID has already been used but not committed in this trigger batch 
                Assignment_Groups__c ag = ags[math.mod(idx, ags.size())];
                    
                //Assign User to Lead as the new owner
                System.debug('>>>>>Owner changed for Lead ' + Trigger.new[i].Id + ' from '+Trigger.new[i].OwnerId+' to '+ ag.User__c);
                Trigger.new[i].OwnerId = ag.User__c;    
                Trigger.new[i].TempOwnerId__c = ag.User__c; 
    
                //Set last assignment datetime
                datetime now = datetime.now();
                ag.Last_Assignment__c = now;
                ag.Millisecond__c = now.millisecondGMT();
                
                //update only latest Assignment Groups per ID
                if (latestAGDateTime.containsKey(ag.id)) {
                    if(latestAGDateTime.get(ag.id) < now) {
                        updateAssignmentGroups.put(ag.id, ag);
                        latestAGDateTime.put(ag.id, now);
                    }
                } else {
                    updateAssignmentGroups.put(ag.id, ag);
                    latestAGDateTime.put(ag.id,now);
                }
                
                idx++;
            }
        }
        //Map --> List/Array for DML update
        List<Assignment_Groups__c> updateAG = new List<Assignment_Groups__c>();
        for (Id agId : updateAssignmentGroups.keySet()) {
            updateAG.add(updateAssignmentGroups.get(agId));
        }
    
        System.debug('>>>>>Update Assignment Groups: '+updateAG);   
        
        //
        //Update last assignment for Assignment Group in batch
        //
        if (updateAG.size()>0) {
            try {
                update updateAG;
            } catch (Exception e){
                for (Integer i : queueIds.keySet())
                {
                    Trigger.new[i].addError('ERROR: Could not update Assignment Group records ' + ' DETAIL: '+e.getMessage());  
                }
            }
        }
    }

 

steve456steve456

can you highlight line 79

Jin D.ax1084Jin D.ax1084

Good point... Done

Jake GmerekJake Gmerek

ags is not getting assigned any values.  You are iterating over queueIds.keyset which looking above is set by idx which is simply an incremented integer with values 0,1,2..., none of these values, which get dumped into i, matches any of the ids that represent the keyset of asgnGroups and so you are not putting anything in ags, which means ags is still NULL and so when you call ags.size() you are dereferencing a NULL object.

Jin D.ax1084Jin D.ax1084

Thanks Jake. Any suggestion on how to modify the code? This is actually from a case round robin assignment that I installed and modified from the appexchange (created by force.com labs).  It's working really well in that it is assigning leads correctly in a round robin but naturally I'd like to avoid the errors.

Jake GmerekJake Gmerek

Hang on, I think that I missed something.  I'll look at it closer and let you know...

Jake GmerekJake Gmerek

Can you post a debug log from one of the executions where it fails?  I have a hunch about what is going on, and I can confirm it with the debug log.

Jin D.ax1084Jin D.ax1084

Apex script unhandled trigger exception by user/organization: 005400000016uMG/00D300000000f5k

 

leadRoundRobin: execution of BeforeUpdate

 

caused by: System.NullPointerException: Attempt to de-reference a null object

 

Trigger.leadRoundRobin: line 79, column 13

 

Debug Log:

20.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;DB,INFO

14:21:43.823 (2823123000)|EXECUTION_STARTED

14:21:43.823 (2823181000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS

14:21:43.823 (2823203000)|CODE_UNIT_STARTED|[EXTERNAL]|01q40000000GwQp|ownerCopy on Lead trigger event BeforeInsert for [new, new]

14:21:43.823 (2823292000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12

14:21:43.823 (2823679000)|STATEMENT_EXECUTE|[1]

14:21:43.823 (2823689000)|STATEMENT_EXECUTE|[3]

14:21:43.823 (2823843000)|VARIABLE_ASSIGNMENT|[3]|x|{"Manual_Territory_Ove (8 more) ...":false,"RecordTypeId":"01240000000USLVAA4","Converted_To_Opportu (7 more) ...":0.0,"Blackberry__c":0.0,"Windows_Mobile_7__c":0.0,"Job_Role__c":"Mobility","jigsaw_clean__Sync_S (18 more) ...":"_IM1_/resource/jigsa (39 more) ...","Virtual_Environment_ (2 more) ...":false,"LeadSource":"Gartner: Critical Ca (18 more) ...","LastName":"Griffin","DoNotCall":false,"request_trade_show_m (9 more) ...":false,"jigsaw_clean__Jigsaw (11 more) ...":0.0,"SFGA__CorrelationID_ (2 more) ...":"none","Star_Rating__c":"_IM1_/img/samples/st (31 more) ...","jigsaw_clean__Sync_S (16 more) ...":"Not Found","UserZPSalesPerson__c":0.0,"Android__c":0.0,"Clustered_Environmen (4 more) ...":false,"Zenprise_Mobile_200_ (2 more) ...":false,"Lead_Source__c":"Gartner: Critical Ca (18 more) ...","jigsaw_clean__Automa (14 more) ...":"Unlocked","jigsaw_clean__Automa (23 more) ...":false,"HasOptedOutOfEmail":false,"jigsaw_clean__Freshe (4 more) ...":"N","Country":"US","Contacted__c":false,"iPhone__c":0.0,"Portal_Lead_Link__c":"https://na2.salesfor (87 more) ...","jigsaw_clean__Jigsaw (11 more) ...":"Unmanaged","Email":"moreece.griffin@chil (9 more) ...","Zenprise_Passed_Lead (3 more) ...":false,"Webinar__c":false,"IsDeleted":false,"Status__c":"Open","SFGA__Web_Source__c":"none","Phone":"214-456-7000","IsConverted":false,"jigsaw_clean__Gravey (6 more) ...":false,"HasOptedOutOfFax":false,"iPad__c":0.0,"Blackberry_Users__c":"- none -","OwnerId":"005400000016uMGAAY","Job_Level__c":"Staff","Call_List__c":false,"Zenprise_Mobile_150_ (2 more) ...":false,"SFGA__Correlation_Da (5 more) ...":"none","IsUnreadByOwner":false,"jigsaw_clean__Duplic (6 more) ...":"None Found","Total_Number_of_Devi (6 more) ...":0.0,"Next_Follow_Up_Day_o (9 more) ...":"Thursday","jigsaw_clean__Jigsaw (19 more) ...":0.0,"FirstName":"Moreece","Evaluation__c":false,"Company":"Childrens Medical Ce (11 more) ...","UnspecifiedDevices__ (1 more) ...":"1001-2500","jigsaw_clean__Silent (10 more) ...":false,"Windows_Mobile__c":0.0,"Treo_Users__c":"- none -","Windows_Mobiles_del_ (2 more) ...":0.0,"request_more_info__c":false,"Status":"Open","Stars__c":"No Score","Symbian__c":0.0,"State":"TX","request_product_demo (3 more) ...":false}|0x41c71e91

14:21:43.823 (2823869000)|STATEMENT_EXECUTE|[3]

14:21:43.823 (2823873000)|STATEMENT_EXECUTE|[6]

14:21:43.823 (2823919000)|STATEMENT_EXECUTE|[6]

14:21:43.823 (2823925000)|STATEMENT_EXECUTE|[7]

14:21:43.823 (2823971000)|VARIABLE_ASSIGNMENT|[7]|this.Owner_Copy__c|"005400000016uMGAAY"|0x41c71e91

14:21:43.823 (2823980000)|STATEMENT_EXECUTE|[10]

14:21:43.824 (2824006000)|HEAP_ALLOCATE|[10]|Bytes:3

14:21:43.824 (2824026000)|STATEMENT_EXECUTE|[10]

14:21:43.824 (2824031000)|STATEMENT_EXECUTE|[11]

14:21:43.824 (2824061000)|VARIABLE_ASSIGNMENT|[11]|this.Owner_Copy__c|"005400000016uMGAAY"|0x41c71e91

14:21:43.824 (2824179000)|VARIABLE_ASSIGNMENT|[3]|x|{"Manual_Territory_Ove (8 more) ...":false,"RecordTypeId":"01240000000USLVAA4","Converted_To_Opportu (7 more) ...":0.0,"Blackberry__c":0.0,"Windows_Mobile_7__c":0.0,"Job_Role__c":"IT / Technical","jigsaw_clean__Sync_S (18 more) ...":"_IM1_/resource/jigsa (39 more) ...","Virtual_Environment_ (2 more) ...":false,"LeadSource":"Web_Form_Quick_Quote","LastName":"Waxon","DoNotCall":false,"request_trade_show_m (9 more) ...":false,"jigsaw_clean__Jigsaw (11 more) ...":0.0,"SFGA__CorrelationID_ (2 more) ...":"none","Star_Rating__c":"_IM1_/img/samples/st (31 more) ...","jigsaw_clean__Sync_S (16 more) ...":"Not Found","UserZPSalesPerson__c":0.0,"Android__c":0.0,"Clustered_Environmen (4 more) ...":false,"Zenprise_Mobile_200_ (2 more) ...":false,"Lead_Source__c":"Web_Form_Quick_Quote","jigsaw_clean__Automa (14 more) ...":"Unlocked","jigsaw_clean__Automa (23 more) ...":false,"HasOptedOutOfEmail":false,"jigsaw_clean__Freshe (4 more) ...":"N","Country":"US","Contacted__c":false,"iPhone__c":0.0,"Portal_Lead_Link__c":"https://na2.salesfor (87 more) ...","jigsaw_clean__Jigsaw (11 more) ...":"Unmanaged","Email":"paul.waxon@decopac.c (2 more) ...","Zenprise_Passed_Lead (3 more) ...":false,"Webinar__c":false,"IsDeleted":false,"Status__c":"Open","SFGA__Web_Source__c":"none","Phone":"7633982631","IsConverted":false,"jigsaw_clean__Gravey (6 more) ...":false,"HasOptedOutOfFax":false,"iPad__c":0.0,"Blackberry_Users__c":"- none -","OwnerId":"005400000016uMGAAY","Job_Level__c":"Staff","Call_List__c":false,"Zenprise_Mobile_150_ (2 more) ...":false,"SFGA__Correlation_Da (5 more) ...":"none","IsUnreadByOwner":false,"jigsaw_clean__Duplic (6 more) ...":"None Found","Total_Number_of_Devi (6 more) ...":0.0,"Next_Follow_Up_Day_o (9 more) ...":"Thursday","jigsaw_clean__Jigsaw (19 more) ...":0.0,"FirstName":"Paul","Evaluation__c":false,"Company":"DecoPac","UnspecifiedDevices__ (1 more) ...":"1-200","jigsaw_clean__Silent (10 more) ...":false,"Windows_Mobile__c":0.0,"Treo_Users__c":"- none -","Windows_Mobiles_del_ (2 more) ...":0.0,"request_more_info__c":false,"Status":"Open","Stars__c":"No Score","Symbian__c":0.0,"State":"MN","request_product_demo (3 more) ...":false}|0x4761b2c2

14:21:43.824 (2824203000)|STATEMENT_EXECUTE|[3]

14:21:43.824 (2824207000)|STATEMENT_EXECUTE|[6]

14:21:43.824 (2824215000)|STATEMENT_EXECUTE|[6]

14:21:43.824 (2824218000)|STATEMENT_EXECUTE|[7]

14:21:43.824 (2824248000)|VARIABLE_ASSIGNMENT|[7]|this.Owner_Copy__c|"005400000016uMGAAY"|0x4761b2c2

14:21:43.824 (2824255000)|STATEMENT_EXECUTE|[10]

14:21:43.824 (2824267000)|HEAP_ALLOCATE|[10]|Bytes:3

14:21:43.824 (2824279000)|STATEMENT_EXECUTE|[10]

14:21:43.824 (2824283000)|STATEMENT_EXECUTE|[11]

14:21:43.824 (2824310000)|VARIABLE_ASSIGNMENT|[11]|this.Owner_Copy__c|"005400000016uMGAAY"|0x4761b2c2

14:21:43.824 (2824344000)|VARIABLE_SCOPE_END|[EXTERNAL]|x

14:21:41.367 (2824323000)|CUMULATIVE_LIMIT_USAGE

14:21:41.367|LIMIT_USAGE_FOR_NS|(default)|

  Number of SOQL queries: 0 out of 100

  Number of query rows: 0 out of 50000

  Number of SOSL queries: 0 out of 20

  Number of DML statements: 0 out of 150

  Number of DML rows: 0 out of 10000

  Number of script statements: 4 out of 200000

  Maximum heap size: 0 out of 3000000

  Number of callouts: 0 out of 10

  Number of Email Invocations: 0 out of 10

  Number of fields describes: 0 out of 100

  Number of record type describes: 0 out of 100

  Number of child relationships describes: 0 out of 100

  Number of picklist describes: 0 out of 100

  Number of future calls: 0 out of 10

 

14:21:41.367 (2824323000)|CUMULATIVE_LIMIT_USAGE_END

 

14:21:43.824 (2824643000)|CODE_UNIT_FINISHED|ownerCopy on Lead trigger event BeforeInsert for [new, new]

14:21:43.830 (2830257000)|ENTERING_MANAGED_PKG|jigsaw_clean

14:21:43.834 (2834413000)|CODE_UNIT_STARTED|[EXTERNAL]|01q40000000Gws6|leadRoundRobin on Lead trigger event BeforeInsert for [new, new]

14:21:43.834 (2834470000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12

14:21:43.834 (2834497000)|STATEMENT_EXECUTE|[1]

14:21:43.834 (2834503000)|STATEMENT_EXECUTE|[5]

14:21:43.834 (2834516000)|VARIABLE_SCOPE_BEGIN|[5]|queueIds|Map|true|false

14:21:43.834 (2834525000)|HEAP_ALLOCATE|[5]|Bytes:4

14:21:43.834 (2834558000)|VARIABLE_ASSIGNMENT|[5]|queueIds|{}|0x34c6acb7

14:21:43.834 (2834565000)|STATEMENT_EXECUTE|[7]

14:21:43.834 (2834572000)|VARIABLE_SCOPE_BEGIN|[7]|idx|Integer|false|false

14:21:43.834 (2834584000)|VARIABLE_ASSIGNMENT|[7]|idx|0

14:21:43.834 (2834589000)|STATEMENT_EXECUTE|[8]

14:21:43.834 (2834807000)|VARIABLE_ASSIGNMENT|[8]|cs|{"Manual_Territory_Ove (8 more) ...":false,"RecordTypeId":"01240000000USLVAA4","Converted_To_Opportu (7 more) ...":0.0,"Blackberry__c":0.0,"Windows_Mobile_7__c":0.0,"Job_Role__c":"Mobility","jigsaw_clean__Sync_S (18 more) ...":"_IM1_/resource/jigsa (39 more) ...","Virtual_Environment_ (2 more) ...":false,"LeadSource":"Gartner: Critical Ca (18 more) ...","LastName":"Griffin","DoNotCall":false,"request_trade_show_m (9 more) ...":false,"jigsaw_clean__Jigsaw (11 more) ...":0.0,"SFGA__CorrelationID_ (2 more) ...":"none","Star_Rating__c":"_IM1_/img/samples/st (31 more) ...","jigsaw_clean__Sync_S (16 more) ...":"Not Found","UserZPSalesPerson__c":0.0,"Android__c":0.0,"Clustered_Environmen (4 more) ...":false,"Zenprise_Mobile_200_ (2 more) ...":false,"Lead_Source__c":"Gartner: Critical Ca (18 more) ...","jigsaw_clean__Automa (14 more) ...":"Unlocked","jigsaw_clean__Automa (23 more) ...":false,"HasOptedOutOfEmail":false,"jigsaw_clean__Freshe (4 more) ...":"N","Country":"US","Contacted__c":false,"iPhone__c":0.0,"Portal_Lead_Link__c":"https://na2.salesfor (87 more) ...","jigsaw_clean__Jigsaw (11 more) ...":"Unmanaged","Email":"moreece.griffin@chil (9 more) ...","Zenprise_Passed_Lead (3 more) ...":false,"Webinar__c":false,"IsDeleted":false,"Status__c":"Open","SFGA__Web_Source__c":"none","Owner_Copy__c":"005400000016uMGAAY","Phone":"214-456-7000","IsConverted":false,"jigsaw_clean__Gravey (6 more) ...":false,"HasOptedOutOfFax":false,"iPad__c":0.0,"Blackberry_Users__c":"- none -","OwnerId":"005400000016uMGAAY","Job_Level__c":"Staff","Call_List__c":false,"Zenprise_Mobile_150_ (2 more) ...":false,"SFGA__Correlation_Da (5 more) ...":"none","IsUnreadByOwner":false,"jigsaw_clean__Duplic (6 more) ...":"None Found","Total_Number_of_Devi (6 more) ...":0.0,"Next_Follow_Up_Day_o (9 more) ...":"Thursday","jigsaw_clean__Jigsaw (19 more) ...":0.0,"FirstName":"Moreece","Evaluation__c":false,"Company":"Childrens Medical Ce (11 more) ...","jigsaw_clean__CRM_La (14 more) ...":1323814901373,"UnspecifiedDevices__ (1 more) ...":"1001-2500","jigsaw_clean__Silent (10 more) ...":false,"Windows_Mobile__c":0.0,"Treo_Users__c":"- none -","Windows_Mobiles_del_ (2 more) ...":0.0,"request_more_info__c":false,"Status":"Open","Stars__c":"No Score","Symbian__c":0.0,"State":"TX","request_product_demo (3 more) ...":false}|0x4ded846f

14:21:43.834 (2834834000)|STATEMENT_EXECUTE|[9]

14:21:43.834 (2834838000)|STATEMENT_EXECUTE|[10]

14:21:43.834 (2834841000)|STATEMENT_EXECUTE|[18]

14:21:43.834 (2834846000)|STATEMENT_EXECUTE|[19]

14:21:43.834 (2834869000)|HEAP_ALLOCATE|[19]|Bytes:-4

14:21:43.834 (2834879000)|STATEMENT_EXECUTE|[21]

14:21:43.834 (2834895000)|VARIABLE_ASSIGNMENT|[21]|idx|1

14:21:43.835 (2835010000)|VARIABLE_ASSIGNMENT|[8]|cs|{"Manual_Territory_Ove (8 more) ...":false,"RecordTypeId":"01240000000USLVAA4","Converted_To_Opportu (7 more) ...":0.0,"Blackberry__c":0.0,"Windows_Mobile_7__c":0.0,"Job_Role__c":"IT / Technical","jigsaw_clean__Sync_S (18 more) ...":"_IM1_/resource/jigsa (39 more) ...","Virtual_Environment_ (2 more) ...":false,"LeadSource":"Web_Form_Quick_Quote","LastName":"Waxon","DoNotCall":false,"request_trade_show_m (9 more) ...":false,"jigsaw_clean__Jigsaw (11 more) ...":0.0,"SFGA__CorrelationID_ (2 more) ...":"none","Star_Rating__c":"_IM1_/img/samples/st (31 more) ...","jigsaw_clean__Sync_S (16 more) ...":"Not Found","UserZPSalesPerson__c":0.0,"Android__c":0.0,"Clustered_Environmen (4 more) ...":false,"Zenprise_Mobile_200_ (2 more) ...":false,"Lead_Source__c":"Web_Form_Quick_Quote","jigsaw_clean__Automa (14 more) ...":"Unlocked","jigsaw_clean__Automa (23 more) ...":false,"HasOptedOutOfEmail":false,"jigsaw_clean__Freshe (4 more) ...":"N","Country":"US","Contacted__c":false,"iPhone__c":0.0,"Portal_Lead_Link__c":"https://na2.salesfor (87 more) ...","jigsaw_clean__Jigsaw (11 more) ...":"Unmanaged","Email":"paul.waxon@decopac.c (2 more) ...","Zenprise_Passed_Lead (3 more) ...":false,"Webinar__c":false,"IsDeleted":false,"Status__c":"Open","SFGA__Web_Source__c":"none","Owner_Copy__c":"005400000016uMGAAY","Phone":"7633982631","IsConverted":false,"jigsaw_clean__Gravey (6 more) ...":false,"HasOptedOutOfFax":false,"iPad__c":0.0,"Blackberry_Users__c":"- none -","OwnerId":"005400000016uMGAAY","Job_Level__c":"Staff","Call_List__c":false,"Zenprise_Mobile_150_ (2 more) ...":false,"SFGA__Correlation_Da (5 more) ...":"none","IsUnreadByOwner":false,"jigsaw_clean__Duplic (6 more) ...":"None Found","Total_Number_of_Devi (6 more) ...":0.0,"Next_Follow_Up_Day_o (9 more) ...":"Thursday","jigsaw_clean__Jigsaw (19 more) ...":0.0,"FirstName":"Paul","Evaluation__c":false,"Company":"DecoPac","jigsaw_clean__CRM_La (14 more) ...":1323814901373,"UnspecifiedDevices__ (1 more) ...":"1-200","jigsaw_clean__Silent (10 more) ...":false,"Windows_Mobile__c":0.0,"Treo_Users__c":"- none -","Windows_Mobiles_del_ (2 more) ...":0.0,"request_more_info__c":false,"Status":"Open","Stars__c":"No Score","Symbian__c":0.0,"State":"MN","request_product_demo (3 more) ...":false}|0x298acc39

14:21:43.835 (2835036000)|STATEMENT_EXECUTE|[9]

14:21:43.835 (2835041000)|STATEMENT_EXECUTE|[10]

14:21:43.835 (2835044000)|STATEMENT_EXECUTE|[18]

14:21:43.835 (2835048000)|STATEMENT_EXECUTE|[19]

14:21:43.835 (2835063000)|HEAP_ALLOCATE|[19]|Bytes:-4

14:21:43.835 (2835071000)|STATEMENT_EXECUTE|[21]

14:21:43.835 (2835085000)|VARIABLE_ASSIGNMENT|[21]|idx|2

14:21:43.835 (2835090000)|STATEMENT_EXECUTE|[23]

14:21:43.835 (2835110000)|HEAP_ALLOCATE|[23]|Bytes:59

14:21:43.835 (2835119000)|USER_DEBUG|[23]|DEBUG|>>>>>queueIds: {0=005400000016uMGAAY, 1=005400000016uMGAAY}

14:21:43.835 (2835125000)|STATEMENT_EXECUTE|[24]

14:21:43.835 (2835137000)|STATEMENT_EXECUTE|[24]

14:21:43.835 (2835142000)|STATEMENT_EXECUTE|[29]

14:21:43.835 (2835149000)|VARIABLE_SCOPE_BEGIN|[29]|asgnGroupNameIds|Map|true|false

14:21:43.835 (2835155000)|HEAP_ALLOCATE|[29]|Bytes:4

14:21:43.835 (2835171000)|VARIABLE_ASSIGNMENT|[29]|asgnGroupNameIds|{}|0x76b8b82c

14:21:43.835 (2835177000)|STATEMENT_EXECUTE|[30]

14:21:43.835 (2835183000)|VARIABLE_SCOPE_BEGIN|[30]|asgnGroupQueues|Map|true|false

14:21:43.835 (2835190000)|HEAP_ALLOCATE|[30]|Bytes:4

14:21:43.835 (2835205000)|VARIABLE_ASSIGNMENT|[30]|asgnGroupQueues|{}|0x3f7a93d6

14:21:43.835 (2835211000)|STATEMENT_EXECUTE|[32]

14:21:43.835 (2835219000)|SOQL_EXECUTE_BEGIN|[32]|Aggregations:0|SELECT Assignment_Group_Name__c, QueueId__c

                                          FROM Assignment_Group_Queues__c

                                          WHERE QueueId__c in :queueIds.values()

                                          AND Active__c = 'True'

14:21:43.835 (2835506000)|HEAP_ALLOCATE|[34]|Bytes:12

14:21:43.842 (2842697000)|SOQL_EXECUTE_END|[32]|Rows:0

14:21:43.842 (2842720000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4

14:21:43.842 (2842745000)|VARIABLE_ASSIGNMENT|[32]|agq|[]|0x17e21f73

14:21:43.842 (2842752000)|STATEMENT_EXECUTE|[36]

14:21:43.842 (2842757000)|STATEMENT_EXECUTE|[37]

14:21:43.842 (2842762000)|STATEMENT_EXECUTE|[37]

14:21:43.842 (2842772000)|VARIABLE_SCOPE_BEGIN|[37]|i|Integer|false|false

14:21:43.842 (2842848000)|VARIABLE_ASSIGNMENT|[37]|i|0

14:21:43.842 (2842870000)|STATEMENT_EXECUTE|[37]

14:21:43.842 (2842887000)|STATEMENT_EXECUTE|[41]

14:21:43.842 (2842905000)|HEAP_ALLOCATE|[41]|Bytes:24

14:21:43.842 (2842913000)|USER_DEBUG|[41]|DEBUG|>>>>>asgnGroupQueues: {}

14:21:43.842 (2842920000)|STATEMENT_EXECUTE|[42]

14:21:43.842 (2842933000)|STATEMENT_EXECUTE|[42]

14:21:43.842 (2842973000)|VARIABLE_SCOPE_END|[EXTERNAL]|i

14:21:43.842 (2842978000)|VARIABLE_SCOPE_END|[EXTERNAL]|agq

14:21:43.842 (2842981000)|VARIABLE_SCOPE_END|[EXTERNAL]|cs

14:21:41.386 (2842945000)|CUMULATIVE_LIMIT_USAGE

14:21:41.386|LIMIT_USAGE_FOR_NS|(default)|

  Number of SOQL queries: 1 out of 100

  Number of query rows: 0 out of 50000

  Number of SOSL queries: 0 out of 20

  Number of DML statements: 0 out of 150

  Number of DML rows: 0 out of 10000

  Number of script statements: 18 out of 200000

  Maximum heap size: 0 out of 3000000

  Number of callouts: 0 out of 10

  Number of Email Invocations: 0 out of 10

  Number of fields describes: 0 out of 100

  Number of record type describes: 0 out of 100

  Number of child relationships describes: 0 out of 100

  Number of picklist describes: 0 out of 100

  Number of future calls: 0 out of 10

 

 

Jin D.ax1084Jin D.ax1084

14:21:41.386|LIMIT_USAGE_FOR_NS|jigsaw_clean|

  Number of SOQL queries: 0 out of 100

  Number of query rows: 0 out of 50000

  Number of SOSL queries: 0 out of 20

  Number of DML statements: 0 out of 150

  Number of DML rows: 0 out of 10000

  Number of script statements: 4 out of 200000

  Maximum heap size: 0 out of 3000000

  Number of callouts: 0 out of 10

  Number of Email Invocations: 0 out of 10

  Number of fields describes: 0 out of 100

  Number of record type describes: 0 out of 100

  Number of child relationships describes: 0 out of 100

  Number of picklist describes: 0 out of 100

  Number of future calls: 0 out of 10

 

14:21:41.386 (2842945000)|CUMULATIVE_LIMIT_USAGE_END

 

14:21:43.843 (2843041000)|CODE_UNIT_FINISHED|leadRoundRobin on Lead trigger event BeforeInsert for [new, new]

14:21:43.844 (2844871000)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Lead:new

14:21:43.844 (2844962000)|CODE_UNIT_FINISHED|Validation:Lead:new

14:21:43.844 (2844990000)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Lead:new

14:21:43.845 (2845070000)|CODE_UNIT_FINISHED|Validation:Lead:new

14:21:44.209 (3209637000)|CODE_UNIT_STARTED|[EXTERNAL]|01q40000000GwGk|AddLeadToDealRegistrationCampaign on Lead trigger event AfterInsert for [00Q4000000cKlxM, 00Q4000000cKlxN]

14:21:44.209 (3209672000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12

14:21:44.209 (3209722000)|STATEMENT_EXECUTE|[1]

14:21:44.209 (3209732000)|STATEMENT_EXECUTE|[4]

14:21:44.209 (3209738000)|STATEMENT_EXECUTE|[4]

14:21:44.209 (3209745000)|STATEMENT_EXECUTE|[5]

14:21:44.209 (3209763000)|VARIABLE_SCOPE_BEGIN|[5]|dealRegId|RecordType|true|false

14:21:44.209 (3209814000)|SOQL_EXECUTE_BEGIN|[5]|Aggregations:0|Select Id from RecordType where name='Deal Registration Request' and SobjectType='Lead'

14:21:44.213 (3213365000)|SOQL_EXECUTE_END|[5]|Rows:1

14:21:44.213 (3213385000)|HEAP_ALLOCATE|[5]|Bytes:8

14:21:44.213 (3213402000)|HEAP_ALLOCATE|[5]|Bytes:32

14:21:44.213 (3213446000)|VARIABLE_ASSIGNMENT|[5]|dealRegId|{"Id":"01240000000USXbAAO"}|0x3397b2bb

14:21:44.213 (3213456000)|STATEMENT_EXECUTE|[6]

14:21:44.213 (3213496000)|HEAP_ALLOCATE|[6]|Bytes:65

14:21:44.213 (3213507000)|USER_DEBUG|[6]|DEBUG|Deal Registration record type: RecordType:{Id=01240000000USXbAAO}

14:21:44.213 (3213517000)|STATEMENT_EXECUTE|[8]

14:21:44.213 (3213525000)|VARIABLE_SCOPE_BEGIN|[8]|c|Campaign|true|false

14:21:44.213 (3213552000)|SOQL_EXECUTE_BEGIN|[8]|Aggregations:0|Select Id from Campaign where Name='Deal Registration Request'

14:21:44.216 (3216963000)|SOQL_EXECUTE_END|[8]|Rows:1

14:21:44.216 (3216986000)|HEAP_ALLOCATE|[8]|Bytes:8

14:21:44.216 (3216999000)|HEAP_ALLOCATE|[8]|Bytes:32

14:21:44.217 (3217034000)|VARIABLE_ASSIGNMENT|[8]|c|{"Id":"70140000000TdldAAC"}|0x2eeacd60

14:21:44.217 (3217045000)|STATEMENT_EXECUTE|[9]

14:21:44.217 (3217086000)|HEAP_ALLOCATE|[9]|Bytes:69

14:21:44.217 (3217099000)|USER_DEBUG|[9]|DEBUG|Deal Registration Request campaign : Campaign:{Id=70140000000TdldAAC}

14:21:44.217 (3217116000)|STATEMENT_EXECUTE|[11]

14:21:44.217 (3217131000)|VARIABLE_SCOPE_BEGIN|[11]|cMemList|LIST|true|false

14:21:44.217 (3217141000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4

14:21:44.217 (3217172000)|VARIABLE_ASSIGNMENT|[11]|cMemList|[]|0x146ae101

14:21:44.217 (3217183000)|STATEMENT_EXECUTE|[13]

14:21:44.217 (3217423000)|VARIABLE_ASSIGNMENT|[13]|l|{"Manual_Territory_Ove (8 more) ...":false,"RecordTypeId":"01240000000USLVAA4","LastTransferDate":1323814901000,"Converted_To_Opportu (7 more) ...":0.0,"Blackberry__c":0.0,"Windows_Mobile_7__c":0.0,"Job_Role__c":"Mobility","jigsaw_clean__Sync_S (18 more) ...":"_IM1_/resource/jigsa (39 more) ...","LastModifiedDate":1323814901000,"Virtual_Environment_ (2 more) ...":false,"LeadSource":"Gartner: Critical Ca (18 more) ...","LastName":"Griffin","DoNotCall":false,"request_trade_show_m (9 more) ...":false,"SFGA__CorrelationID_ (2 more) ...":"none","jigsaw_clean__Jigsaw (11 more) ...":0.0,"Star_Rating__c":"_IM1_/img/samples/st (31 more) ...","jigsaw_clean__Sync_S (16 more) ...":"Not Found","UserZPSalesPerson__c":0.0,"Android__c":0.0,"Clustered_Environmen (4 more) ...":false,"Zenprise_Mobile_200_ (2 more) ...":false,"Lead_Source__c":"Gartner: Critical Ca (18 more) ...","jigsaw_clean__Automa (14 more) ...":"Unlocked","jigsaw_clean__Automa (23 more) ...":false,"HasOptedOutOfEmail":false,"Country":"US","jigsaw_clean__Freshe (4 more) ...":"N","Contacted__c":false,"iPhone__c":0.0,"Portal_Lead_Link__c":"https://na2.salesfor (102 more) ...","Email":"moreece.griffin@chil (9 more) ...","jigsaw_clean__Jigsaw (11 more) ...":"Unmanaged","Zenprise_Passed_Lead (3 more) ...":false,"CreatedById":"005400000016uMGAAY","Webinar__c":false,"IsDeleted":false,"Id":"00Q4000000cKlxMEAS","Status__c":"Open","SFGA__Web_Source__c":"none","Owner_Copy__c":"005400000016uMGAAY","OwnerUserType__c":"Standard","Phone":"214-456-7000","IsConverted":false,"Zenprise_Account_ID_ (2 more) ...":"20111297684","jigsaw_clean__Gravey (6 more) ...":false,"HasOptedOutOfFax":false,"iPad__c":0.0,"Blackberry_Users__c":"- none -","OwnerId":"005400000016uMGAAY","Job_Level__c":"Staff","Call_List__c":false,"Zenprise_Mobile_150_ (2 more) ...":false,"SFGA__Correlation_Da (5 more) ...":"none","IsUnreadByOwner":true,"jigsaw_clean__Duplic (6 more) ...":"None Found","Total_Number_of_Devi (6 more) ...":0.0,"Next_Follow_Up_Day_o (9 more) ...":"Thursday","SystemModstamp":1323814901000,"Lead_Age_Hours__c":0.0,"FirstName":"Moreece","jigsaw_clean__Jigsaw (19 more) ...":0.0,"Evaluation__c":false,"Company":"Childrens Medical Ce (11 more) ...","jigsaw_clean__CRM_La (14 more) ...":1323814901000,"UnspecifiedDevices__ (1 more) ...":"1001-2500","jigsaw_clean__Silent (10 more) ...":false,"LastModifiedById":"005400000016uMGAAY","Windows_Mobile__c":0.0,"Treo_Users__c":"- none -","Windows_Mobiles_del_ (2 more) ...":0.0,"request_more_info__c":false,"Status":"Open","Stars__c":"No Score","Symbian__c":0.0,"State":"TX","CreatedDate":1323814901000,"request_product_demo (3 more) ...":false}|0x64e9daf9

14:21:44.217 (3217463000)|STATEMENT_EXECUTE|[13]

14:21:44.217 (3217472000)|STATEMENT_EXECUTE|[14]

14:21:44.217 (3217522000)|STATEMENT_EXECUTE|[14]

14:21:44.217 (3217742000)|VARIABLE_ASSIGNMENT|[13]|l|{"Manual_Territory_Ove (8 more) ...":false,"RecordTypeId":"01240000000USLVAA4","LastTransferDate":1323814901000,"Converted_To_Opportu (7 more) ...":0.0,"Blackberry__c":0.0,"Windows_Mobile_7__c":0.0,"Job_Role__c":"IT / Technical","jigsaw_clean__Sync_S (18 more) ...":"_IM1_/resource/jigsa (39 more) ...","LastModifiedDate":1323814901000,"Virtual_Environment_ (2 more) ...":false,"LeadSource":"Web_Form_Quick_Quote","LastName":"Waxon","DoNotCall":false,"request_trade_show_m (9 more) ...":false,"SFGA__CorrelationID_ (2 more) ...":"none","jigsaw_clean__Jigsaw (11 more) ...":0.0,"Star_Rating__c":"_IM1_/img/samples/st (31 more) ...","jigsaw_clean__Sync_S (16 more) ...":"Not Found","UserZPSalesPerson__c":0.0,"Android__c":0.0,"Clustered_Environmen (4 more) ...":false,"Zenprise_Mobile_200_ (2 more) ...":false,"Lead_Source__c":"Web_Form_Quick_Quote","jigsaw_clean__Automa (14 more) ...":"Unlocked","jigsaw_clean__Automa (23 more) ...":false,"HasOptedOutOfEmail":false,"Country":"US","jigsaw_clean__Freshe (4 more) ...":"N","Contacted__c":false,"iPhone__c":0.0,"Portal_Lead_Link__c":"https://na2.salesfor (102 more) ...","Email":"paul.waxon@decopac.c (2 more) ...","jigsaw_clean__Jigsaw (11 more) ...":"Unmanaged","Zenprise_Passed_Lead (3 more) ...":false,"CreatedById":"005400000016uMGAAY","Webinar__c":false,"IsDeleted":false,"Id":"00Q4000000cKlxNEAS","Status__c":"Open","SFGA__Web_Source__c":"none","Owner_Copy__c":"005400000016uMGAAY","OwnerUserType__c":"Standard","Phone":"7633982631","IsConverted":false,"Zenprise_Account_ID_ (2 more) ...":"20111297685","jigsaw_clean__Gravey (6 more) ...":false,"HasOptedOutOfFax":false,"iPad__c":0.0,"Blackberry_Users__c":"- none -","OwnerId":"005400000016uMGAAY","Job_Level__c":"Staff","Call_List__c":false,"Zenprise_Mobile_150_ (2 more) ...":false,"SFGA__Correlation_Da (5 more) ...":"none","IsUnreadByOwner":true,"jigsaw_clean__Duplic (6 more) ...":"None Found","Total_Number_of_Devi (6 more) ...":0.0,"Next_Follow_Up_Day_o (9 more) ...":"Thursday","SystemModstamp":1323814901000,"Lead_Age_Hours__c":0.0,"FirstName":"Paul","jigsaw_clean__Jigsaw (19 more) ...":0.0,"Evaluation__c":false,"Company":"DecoPac","jigsaw_clean__CRM_La (14 more) ...":1323814901000,"UnspecifiedDevices__ (1 more) ...":"1-200","jigsaw_clean__Silent (10 more) ...":false,"LastModifiedById":"005400000016uMGAAY","Windows_Mobile__c":0.0,"Treo_Users__c":"- none -","Windows_Mobiles_del_ (2 more) ...":0.0,"request_more_info__c":false,"Status":"Open","Stars__c":"No Score","Symbian__c":0.0,"State":"MN","CreatedDate":1323814901000,"request_product_demo (3 more) ...":false}|0x5d991be8

14:21:44.217 (3217783000)|STATEMENT_EXECUTE|[13]

14:21:44.217 (3217791000)|STATEMENT_EXECUTE|[14]

14:21:44.217 (3217804000)|STATEMENT_EXECUTE|[14]

14:21:44.217 (3217812000)|STATEMENT_EXECUTE|[21]

14:21:44.217 (3217836000)|STATEMENT_EXECUTE|[21]

14:21:44.217 (3217889000)|VARIABLE_SCOPE_END|[EXTERNAL]|l

14:21:41.761 (3217854000)|CUMULATIVE_LIMIT_USAGE

14:21:41.761|LIMIT_USAGE_FOR_NS|(default)|

  Number of SOQL queries: 3 out of 100

  Number of query rows: 2 out of 50000

  Number of SOSL queries: 0 out of 20

  Number of DML statements: 0 out of 150

  Number of DML rows: 0 out of 10000

  Number of script statements: 26 out of 200000

  Maximum heap size: 0 out of 3000000

  Number of callouts: 0 out of 10

  Number of Email Invocations: 0 out of 10

  Number of fields describes: 0 out of 100

  Number of record type describes: 0 out of 100

  Number of child relationships describes: 0 out of 100

  Number of picklist describes: 0 out of 100

  Number of future calls: 0 out of 10

 

 

Jake GmerekJake Gmerek

Hey,

So I dug through it and it is similar to what I thought, but interesting.

 

Why it is erroring out on line 79 I have no idea, because, according to the debug log, the code is not reaching line 79, it is actually exiting on line 42:

 

14:21:43.842 (2842913000)|USER_DEBUG|[41]|DEBUG|>>>>>asgnGroupQueues: {}
14:21:43.842 (2842920000)|STATEMENT_EXECUTE|[42]
14:21:43.842 (2842933000)|STATEMENT_EXECUTE|[42]

 

Line 42 looks like this:

if (asgnGroupQueues.isEmpty()) return;

 

essentially since that array is empty the program is exiting.

 

asgnGroupQueues is empty because agq is not being set by this select statement:

 

SELECT Assignment_Group_Name__c, QueueId__c
FROM Assignment_Group_Queues__c
WHERE QueueId__c in :queueIds.values()
AND Active__c = 'True'

 

Essentially that is where you need to start your debugging on this issue is by finding out why that query is returning 0 rows.  This may not be an easy task, but it is probably the result of bad data somewhere.  You do have 2 QueueIds being returned as seen on this line:

 

14:21:43.835 (2835119000)|USER_DEBUG|[23]|DEBUG|>>>>>queueIds: {0=005400000016uMGAAY, 1=005400000016uMGAAY}

 

but apparently neither of those match any of the IDs in teh QueueId__c field on the Assignment_Group_Queues__c object.  I am guessing that this is why the error only occurs intermittently, i.e. only when the data does not match up.  If I were you I would test this using the force.com explorer:

 

http://wiki.developerforce.com/page/ForceExplorer

 

You can use that to run the query independently and ensure that those two ID's do not exisit in that field, you will probably have to change IN: to = adn run one ID at a time.

 

Then comes the hard part:  You have to figure out why the data is wrong (assuming that it is) and then you can see how to fix it.  If you can not ensure that the QueueID__c exists then you can in thoery exit the program if agq is not set with something like:

 

if (agq.isEmpty()) return;

 

However, even though that should solve the error that you are getting (but maybe not since it is calling the error on line 79), it would cause the code not to complete in these instances and you would likely not get the desired functionality.  You could also add:

 

if (ags.isEmpty()) return;

 

on line 78 to try and stop the error, but again the program would exit prematurely in the cases where ags is not getting set.

 

All in all it is a fairly complicated issue that is sort of a judgement call on how to handle, ideally the data can be corrected, but it may require a workaround.

 

I hope this helps, let me know if you have questions.

Jin D.ax1084Jin D.ax1084

WOW, thank you so much!

Jake GmerekJake Gmerek

No problem!!

TbomTbom

It appears you got what you needed.  However I noticed in your original example, the incrementer of "idx++" is inside the "if" block within the "for" loop.  Wouldn't be appropriate to have it outside the if?

 

I'm actually debugging the same code for someone now.

Doug Heindel 1Doug Heindel 1
Has anyone found the bug here? I am working through this issue now. Any insight is appreciated.