You need to sign in to do that
Don't have an account?

trigger de-referencing a null object error
I have a trigger that is supposed to change our Substatus depending on the Case Owner(profile or queue name)
right now it will only work if I choose a Queue or Partner user. If I try to click Change next to Case Owner and assign the Case to a User it gives me the following error:
Error: Apex trigger CW_Update_Substatus_based_on_Case_Owner caused an unexpected exception, contact your administrator: CW_Update_Substatus_based_on_Case_Owner: execution of BeforeUpdate
caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.CW_Update_Substatus_based_on_Case_Owner: line 10, column 1
I've made this trigger as simple as possible and created 2 formula fields, one to show the queue name if the case is assigned to a queue(CW_Queue_Case_Owner__c) and one to show the profile ID if the case is assigned to a user(CW_Owner_Profile__c). I have no idea what else could possibly be wrong. Please help!
trigger CW_Update_Substatus_based_on_Case_Owner on Case (before update, after update)
{
//Set<Id> ownerIds = new Set<Id>();
for(Case objCase : Trigger.new){
//ownerIds.add(objCase.OwnerId);
}
for (Case objCase : Trigger.new)
{
if(objCase.CW_Owner_Profile__c == '00e30000001aw4D'||objCase.CW_Queue_Case_Owner__c.contains('Dealer'))
{
objCase.Substatus__c = 'Open with Dealer';
}else{
if((objCase.CW_Owner_Profile__c =='00e30000001c54i' || objCase.CW_Owner_Profile__c =='00ea0000001ds8w') || objCase.CW_Queue_Case_Owner__c.contains('T2'))
{
objCase.Substatus__c = 'Open with Support Advocates';
}else{
objCase.OwnerId = '00G30000001oUSL';
objCase.Substatus__c = 'Open with Product Specialists';
}
}
}
}
right now it will only work if I choose a Queue or Partner user. If I try to click Change next to Case Owner and assign the Case to a User it gives me the following error:
Error: Apex trigger CW_Update_Substatus_based_on_Case_Owner caused an unexpected exception, contact your administrator: CW_Update_Substatus_based_on_Case_Owner: execution of BeforeUpdate
caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.CW_Update_Substatus_based_on_Case_Owner: line 10, column 1
I've made this trigger as simple as possible and created 2 formula fields, one to show the queue name if the case is assigned to a queue(CW_Queue_Case_Owner__c) and one to show the profile ID if the case is assigned to a user(CW_Owner_Profile__c). I have no idea what else could possibly be wrong. Please help!
trigger CW_Update_Substatus_based_on_Case_Owner on Case (before update, after update)
{
//Set<Id> ownerIds = new Set<Id>();
for(Case objCase : Trigger.new){
//ownerIds.add(objCase.OwnerId);
}
for (Case objCase : Trigger.new)
{
if(objCase.CW_Owner_Profile__c == '00e30000001aw4D'||objCase.CW_Queue_Case_Owner__c.contains('Dealer'))
{
objCase.Substatus__c = 'Open with Dealer';
}else{
if((objCase.CW_Owner_Profile__c =='00e30000001c54i' || objCase.CW_Owner_Profile__c =='00ea0000001ds8w') || objCase.CW_Queue_Case_Owner__c.contains('T2'))
{
objCase.Substatus__c = 'Open with Support Advocates';
}else{
objCase.OwnerId = '00G30000001oUSL';
objCase.Substatus__c = 'Open with Product Specialists';
}
}
}
}
As your trigger is update trigger , you can create a formula field(Boolean) output and check the
CW_Queue_Case_Owner__c.contains value and return true/false in this newly created formula.
By doing this, you dont need to update the trigger but it will be a simple formula field change and you can compaire multiple values using formula.
https://success.salesforce.com/answers?id=90630000000glSdAAI
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.