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
chiranthchiranth 

How to match the record type name in trigger!!

Hi

 

In opportunity object i need to write apex trigger to send a email notification if stage is closed won and RecordType name is xyz.

Im not able to match the record type name, since I have 10 record type, I need to send a email based on the record type.

Plz help on this.

Thanks

HariDineshHariDinesh

Hi,

 

In Apex you can get the information related to record type by below mentioned way

For EX: if you want to get record type id then

 

ID rectypeid = Schema.SObjectType.customobject__c.getRecordTypeInfosByName().get('recordtypename').getRecordTypeId();

Here replace customobject__c with your object name and recordtypename with your recordtypename.

So you can use above syntax and get any information related to Record Type.

 

Refer Below link which will guide you in proper way to understand and you can use it for your scenario. 

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject_describe.htm

 

 

 

Jia HuJia Hu

Use the RecordTypeId field on the Opportunity to filter the RecordType,

In your Trigger, query like
List<Opportunity> opplist = [Select Name from Opportunity Where RecordType.Name = 'AutoLease'];

 

Doc:

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_opportunity.htm

HariDineshHariDinesh

Hi,

 

Yes the above mentioned way like where RecordType.Name is also simple for you to Query.