How to Query the RecordTypeId dynamically for use in Apex Trigger / Class
8:36 PMSalesforce Documentation: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_recordtype.htm
You might have to set or update the RecordType of records dynamically using Apex Triggers. In such cases, the RecordTypeId should be queried and fetched at runtime using the below two approaches.
SOQL:
RecordType RecType = [Select Id From RecordType Where SobjectType = 'Contact' and DeveloperName = 'Strategic_Contact'];
The Developer name corresponds to the RecordType Name as shown below.The other method is to use the Describe call.
MaprtMapByName = d.getRecordTypeInfosByName(); Schema.RecordTypeInfo rtByName = rtMapByName.get('Strategic_Contact');
0 comments