Hello friends, In this post we will see a code example that helps you to get default assigned recordtype of any object for current user. So without wasting time let's get started.
Get profile's default recordtype using apex
To build this code example I had used Account sobject but you can use any of the salesforce object as per your need/requirments.
Code Example:
Id defaultRecordTypeId; String defaultRecordTypeName; String defaultRecordTypeDeveloperName; List<Schema.RecordTypeInfo> infos = Schema.SObjectType.Account.RecordTypeInfos; for (Schema.RecordTypeInfo info : infos) { if (info.DefaultRecordTypeMapping) { defaultRecordTypeId = info.RecordTypeId; defaultRecordTypeName = info.Name; defaultRecordTypeDeveloperName = info.Developername; } } System.debug('DefaultRecordTypeId***'+defaultRecordTypeId); System.debug('DefaultRecordTypeName***'+defaultRecordTypeName); System.debug('DefaultRecordTypeDeveloperName***'+defaultRecordTypeDeveloperName);Output:
Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.
0 Comments
Post a Comment