+ Start a Discussion

how to identify record type in trigger

I'm going to create a trigger on case object, this trigger should only invoke when the case're record type is "XXX", "XXX" is one of the record type of case, can someone help me figure out the code to identify the report type is "XXX". the following script doesn't work.

if(Trigger.new[i].RecordType == 'Partner Case'){

Best Answer chosen by Admin (Salesforce Developers) 
if(Trigger.new[i].RecordTypeId == '000xxx000xxx000')

All Answers

if(Trigger.new[i].RecordTypeId == '000xxx000xxx000')
This was selected as the best answer

Thanks! However, how to identify the recordtypeid? I only know the name, such as "Partner Case".


Use Apex explorer or Saelsforce Schema to find out the recordtypeid of any recordtype


The query wud like as:

Select Id, Name from RecordType



hope it helps :)

Message Edited by crmexpert on 04-15-2009 03:12 AM

Re below, you can just assign the id you want to check for to a variable using a select like below, and then compare to the record in the trigger:



Id PartnerCaseId = [Select Id, Name from RecordType where name = 'Partner Case' limit 1].Id;//Then compare:if(Trigger.new[i].RecordTypeId == PartnerCaseId)


There is also a a specific method to query for the record types for an object, though just doing a Select as suggested should be enough for you. But for more info about the Method, look in the apex docs and search for record types


Thanks very much for your information, I just downloaded app explorer, is it just for test, so I do some change will not affect the product.

And, can it connect to sandbox?

Message Edited by youji37 on 04-15-2009 06:14 PM

You can point Apex Explorer at the sandbox - go to Tools - Options, and change the end point to test.salesforce.com


Then you can login with your Sandbox credentials