function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MBarnardMBarnard 

Custom Validation errors while saving record(s) on Delete - after deployment of APEX Trigger

Hey Guys,

 

Having some issues with an APEX code that I have deployed.

 

When attempting to delete a task I am getting the following error:

 

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger qc.TaskTrigger caused an unexpected exception, contact your administrator: qc.TaskTrigger: execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object: (qc)". 

 

 

My APEX Trigger:

trigger ActivityAccountDetails on Task (before insert, before update) {
// Goal: Find the Account Status of the Account that a task is related to
// and update the Account_Status__c field on the task object with the value

// If related to an Account, query to find out the Account Status

// Create collection of tasks that are related to an Acct (where the Acct is listed only once)
	Set<Id> acctIds = new Set<Id>();
	for(Task t : trigger.new){
		String wId = t.WhatId;
		if(wId!=null && wId.startsWith('001') && !acctIds.contains(t.WhatId)){
			acctIds.add(t.WhatId);
		}
	}
	// Pull in acct ids and related field to populate task record
	List<Account> taskAcct = [Select Id, Account_Status__c from Account where Id in :acctIds];
	Map<Id, Account> acctMap = new Map<Id, Account>();
	for(Account a : taskAcct){
		acctMap.put(a.Id,a);
	}
	// Update custom task field with custom opp field
	for(Task t : trigger.new){
		String wId = t.WhatId;
		if(wId!=null && wId.startswith('001')){
			Account thisAcct = acctMap.get(t.WhatId);
			if(thisAcct!=null){t.Account_Status__c = thisAcct.Account_Status__c;} 
		}
	}

 Test Class:

@isTest
private class MyTest {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        Account testAccount = new Account(name='Test Company Name');
        insert testAccount;
        
        testAccount.Account_Status__c='Prospect: Open';
        update testAccount;
              
        Task testTask = new Task(Subject= 'Test Task', WhatID = testAccount.Id);
        
       
        Account accountInfo = [SELECT Account_Status__c FROM Account WHERE Id = :testAccount.Id];
          
        System.assertEquals(accountInfo.Account_Status__c, testtask.Account_Status__c);
        
        insert testTask;
              
        System.assertEquals(testtask.AccountId, testAccount.Id);
    }
} 

 

Debug Log Detail

pex Debug Log Detail
User	test	Date	11/15/2013 5:02:44 PM EST
Status	Attempt to de-reference a null object	Application	Browser
Request Type	Application	Operation	/setup/own/deleteredirect.jsp
Duration (ms)	74	Log Size (bytes)	170
Log	
19.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
17:02:44.042 (42701000)|ENTERING_MANAGED_PKG|qc

 

 

Any input is greatly appreciated!

 

Thanks!

Mike

digamber.prasaddigamber.prasad

Hi Mike,

 

Since the trigger you are referring in above code is only on 'before insert' & 'before update' event, so be sure that it is not your trigger which is causing this exception.

 

By looking into error message & debug log, looks like you have some managed package named 'qc', which has a trigger 'TaskTrigger' and it is causing exception. It will be helpful to get in touch with the managed package provider and they will help you in getting rid off this exception. We as developers cann't modify/debug code base of a managed package.

 

Hope this will help you!

 

Happy to help you!

 

Regards,

Digamber Prasad

MBarnardMBarnard

That explains it...

 

I was told it was my APEX trigger and took a look and just assumed it was (since this was the first trigger I have ever created).

 

But that solves that problem.