How do I get a given profile's default RecordType for Opportunity?
The closest I can get is the default record type for the current user:
//find all Opportunity record types
List<Schema.RecordTypeInfo> infos = Schema.SObjectType.Opportunity.RecordTypeInfos;
Id defaultRecordTypeId;
//check each one
for (Schema.RecordTypeInfo info : infos) {
if (info.DefaultRecordTypeMapping) {
defaultRecordTypeId = info.RecordTypeId;
}
}
//here is the default Opportunity RecordType Id for the current user
System.debug(defaultRecordTypeId);
Got it....
if (ApexPages.currentPage().getParameters().get('RecordType') == null) {
Schema.DescribeSObjectResult describeOpp = Schema.SObjectType.Opportunity;
List<Schema.RecordTypeInfo> rtInfos = describeOpp.getRecordTypeInfos();
for(Schema.RecordTypeInfo rtInfo : rtInfos) {
if(rtInfo.isDefaultRecordTypeMapping()) {
ApexPages.currentPage().getParameters().put('RecordType', rtInfo.getRecordTypeId());
break;
}
}
}
String recordRT = ApexPages.currentPage().getParameters().get('RecordType');