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
ShikibuShikibu 

recordtypeid not provided with "new" override if profile permits only one recordtype

I have a VF page that overrides the "new" button. 

If the user's profile permits several recordtypes, then the user is shown the setup/ui/recordtypeselect.jsp url first, and the selected r/t is passed as an url parameter, so all is well.
 
However, if the user's profile permits access to only a single r/t, then the vf page controller receives no indication (that I can discover) of the recordtype. ApexPages.currentPage().getParameters() has no "RecordType" entry, and (Case)stdController.getRecord() has RecordTypeId value of null. 
 
How can I discover the correct r/t? We strive to limit our users to a single r/t, because it decreases the number of page loads required to create a new case.
 
 
David VPDavid VP

 This will probably get you going :

 

 

RecordType rt = [select id,name from RecordType where SobjectType='Account' limit 1]; Schema.DescribeSObjectResult d = Schema.SObjectType.Account; Map<Id,Schema.RecordTypeInfo> rtMapById = d.getRecordTypeInfosById(); Schema.RecordTypeInfo rtById = rtMapById.get(rt.id); Map<String,Schema.RecordTypeInfo> rtMapByName = d.getRecordTypeInfosByName(); Schema.RecordTypeInfo rtByName = rtMapByName.get(rt.name); System.assertEquals(rtById,rtByName);

 

 For a full explanation, see :

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

 

 

ShikibuShikibu

David,

 

In this case, I am overriding "New", so my controller extension constructor fetches a record that does not yet exist in the database, and does not have an id.

 

I figure that Salesforce can let me know the recordtype id either by setting Case.RecordTypeId (which is null) or by providing it in the url (it's not there).

 

And yet, the information must be there somewhere, because if my controller saves the record, the recordtypeid is correct, although my controller has not set the value. 

ThomasTTThomasTT

I got you. Your post is always interesting... it could happen to me.

You already tried what I think first, which made it easy.

 

RecordTypeInfo.isAvailable()

 

(you know how to get that, right? pervious answerer post the code)

 

From manual

Returns true if this record type is available to the current user, false otherwise. Use this method to
isAvailable Boolean display a list of available record types to the user when he or she is creating a new record.

 

I didn't know that... interesting. I didn't try it, but could you try it and report us, please?

 

ThomasTT

Message Edited by ThomasTT on 10-28-2009 12:32 AM