You need to sign in to do that
Don't have an account?
Ravi K 47
Issues while deleting task— throwing NullPointerException: Attempt to de-reference a null object error
My requirement is Do not permit any users in any profile except 'System Administrator','Standard User' to delete tasks where Left 3 characters of the WhatId = ‘a0P’(DeleteTask__c) and Type(type__c) = ‘Test’
Issue is While deleting Task from other objects(like account,contact) throwing NullPointerException: Attempt to de-reference a null object error
Below is the complete Error message
trigger TaskBeforeDelete on Task (before delete) { Map<Id,Profile> profileMap=new Map<Id,Profile>([SELECT Id,Name FROM Profile WHERE Name Not IN ('System Administrator','Standard User')]); profile p=profileMap.get(UserInfo.getprofileID()); system.debug('Profile ==>'+p); for (Task task : Trigger.old) { if(task.type__c.equalsIgnoreCase('Test') && (p==null)&& task.WhatId != null && task.WhatId.getSObjectType() == == Deletetask__c.sObjectType) { task.addError('You are not permitted to delete this task'); } } }
Issue is While deleting Task from other objects(like account,contact) throwing NullPointerException: Attempt to de-reference a null object error
Below is the complete Error message
Validation Errors While Saving Record(s)There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger TaskBeforeDelete1 caused an unexpected exception, contact your administrator: TaskBeforeDelete1: execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.TaskBeforeDelete1: line 11, column 1".Can any one please help to resolve the issue
Let us know if this will help you
All Answers
Ravi,
Please follow this code -:
Here you will provide the id of system admin and standard user, because it's a best practice.
Please mark as best answer if it solve your issue.
Thanks
Include type value also, in if condition, which I missed
Thanks
Let us know if this will help you