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
Zachary B.Zachary B. 

Execute an email trigger to exclude a case record type?

Hi Everyone,

Currently we have a custom email object, that we are trying to migrate away from. I am trying to have the class which contains status updates, and queue re-assignment actions, to only trigger if the case is a certain record type. 

The code used to trigger on (before insert, before update, before delete, after insert, after update, after delete) , however I was running into countless errors with that. 

What I currently have is below, but  it is just not running the class at all. This means it is running my workflow rule actions on every record type, instead of just the one I want on the trigger. 

trigger CompanyEmailMessageTrigger on Company_Email_Message__c (after update, after delete, after undelete)
ID rectypeid ='Support_Request_1').getRecordTypeId();

if (rectypeID !='Support_Request_1')

Zachary B.Zachary B.
I mean not to trigger on the record type Support Request, pardon me. 
This line:'Support_Request_1').getRecordTypeId();

Returns a Salesforce Id so it will never equal 'Support_Request_1' as I imagine that is the record type name?

Also I am not sure how you are determining what Case recordType is being used.  The Trigger is running in the context of the Company_Email_Message__c object so there is currently no reference to Case object.

So does Company_Email_Meaasge__c have the record type 'Support_Request_1' . If that is a Case record type, then this logic needs to exist in a case trigger.

I may be missing something maybe expanding exactly what you are tryingt o accomplish would help.  Like "When the Case of record Type "X" updates I want to fire method b in class c"
Zachary B.Zachary B.

You are right @AngrySloth , I don't have the logic connecting it to the case object. 


The company Email Message object does not have the record type "Support Request 1" 


So right now, the class being executed, CompanyEmailMessageTriggeRHandler, has code that changes the status of a case when a new email is received, and re-assigns the case to the appropriate queue by line of business. I want this class to be triggered on the condition that the case is not the support request record type, so the case status is not being changed on a new email, and it is not being re-assigned to the Queue. 

So it looks like what i'm missing is:

Referencing the case object from our custom Email object 
Identifying the developername of the recordtype 
Then triggering the entire class if the record type is NOT support request. 

I appreciate any pointers you may have, I really do appreciate it!