+ Start a Discussion
MattMet86MattMet86 

Trigger - If What.Type.equals()

Need a little help. I can't figure out the correct syntax to utilize Task What.Type in my trigger. Can someone tell me what I am doing wrong?
 
trigger ININRelatedToFix on Task (after Insert, after Update) {
    
    //Get Record Type    
    RecordType Five9Rec = [select id from RecordType where name = 'Five9 Call' AND sobjecttype = 'Task' limit 1];
    system.debug('RecordType= '+Five9Rec.Id);
    
    //Create List for bulkified update
    List<Task> taskList = new List<Task>();
    
    //Loop through each task handed to trigger
    for (Task T : Trigger.new) {
        
        //If Call is related to Employee Session instead of Employee
        //*******************
        If(T.What.Type.equals('Employee_Session__c') && T.RecordTypeId == Five9Rec.Id){
            
            //Get the employee
            Employee_Session__c Emp = [Select Employee__c FROM Employee_Session__c WHERE ID = :T.WhatId];
            
            //Fix Relationship
            T.WhatId = Emp.Employee__c;
            taskList.add(t);
        }
    }
    
    //Builify Update
    update tasklist;
}

 
Best Answer chosen by MattMet86
MattMet86MattMet86
I got the answer from someone else not on this thread. I need to do this:
If(T.WhatId.getSObjectType() == Employee_Session__c.sObjectType && T.RecordTypeId == Five9Rec.Id){


 

All Answers

mike_merinomike_merino
here's an example of something I currently use

if(t.WhoId!=null && t.Who.type== 'Lead')
MattMet86MattMet86
I got the answer from someone else not on this thread. I need to do this:
If(T.WhatId.getSObjectType() == Employee_Session__c.sObjectType && T.RecordTypeId == Five9Rec.Id){


 
This was selected as the best answer