I've to find out the default record type of an Object so that I can use in Apex to insert/update records.

Found out that it is at the user level(user profile based). Is there any other way which I can use to find out the default record type of an object.

It makes sense why it is at the user level, but just out of curiosity I'm looking for another option to get irrespective of the user profile.

  • I'm wondering about your need to know the default record type. When apex code executes as a user, the sobject record that will be created will have the record type which is default for the users profile for that sObject. – techtrekker Oct 15 '12 at 6:35
  • That is correct! I over thought the problem! Thanks! – Vignesh Damodharan Oct 15 '12 at 7:02
  • Happens all the time ;) – techtrekker Oct 15 '12 at 7:07

You can use apex describe to get the record type details of any object. This information will be correct for the running user.

Schema.DescribeSObjectResult dsr = Account.SObjectType.getDescribe();
Schema.RecordTypeInfo defaultRecordType;
for(Schema.RecordTypeInfo rti : dsr.getRecordTypeInfos()) {
    if(rti.isDefaultRecordTypeMapping()) {
        defaultRecordType = rti;
  • As techtrekker said, that was unnecessary. But on the other hand, the snippet worked as expected! Thanks! – Vignesh Damodharan Oct 15 '12 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.