0

I am using record types to filter a picklist. The issue I'm running into is my visualforce page will not display ON NEW the record type no matter what I do. I'm using the syntax {!myObject.recordtype.name} and also check Apex. The record type saves and shows properly on the standard page, the detail screen, and the edit page.

In my Apex controller on NEW record, if I put

system.debug(myObject.RecordType.name) //I get null on NEW 

But when I put do that on the edit screen

system.debug(myObject.RecordType.name) //I get my record type on the debug log

Because the record type is on the screen in the edit page, the picklist filters. Because it's not on the NEW page, the picklist will not filter.

I cannot get access to the assigned record type on new

NEW PAGE

New Page

EDIT PAGE

EDIT PAGE

  • But what does RecordTypeId show? I don't think Visualforce can automatically query relationships until there's something to query. – sfdcfox Sep 26 '17 at 14:23
  • In Apex it debugs as Null on New, and 'MyRecordTypeName' on edit. So sometime after save, the record type is getting set. I had it on an Controller extension but I just changed it to my controller (took a little work but I thought the extension may be the issue) – tjcinnamon Sep 26 '17 at 14:41
  • Where is your new page being generated from? It appears to be an override, are you overriding a standard button, or navigating to this page elsewhere. Are more than 1 record types available for your object, and how is it supposed to know what record type to show on the new? – JRiffe Sep 26 '17 at 16:28
  • there is only 1 record type available so by default that selection screen is overidden. I need to assign the record type in the constructor of the controller for an overridden visualforce page. That allows my picklists to update properly on page load. – tjcinnamon Sep 27 '17 at 22:02
2

On new, if there is no record type specified, it will save with the default record type AFTER save, but not during the record initialize. If you are creating the new record in your controller, you are going to have to set the record type, either by query string or in your controller. The edit page will have the record type because the record has already been saved with the default record type.

| improve this answer | |
  • This worked! I assigned the recordtype in the constructor and the picklists adhered on NEW and (obviously) on EDIT. – tjcinnamon Sep 27 '17 at 22:03
1

The default record type is assigned when you do the DML operation. Thus the instance of record you are showing in the Visualforce page doesn't have a Record Type.

A quickfix would be , to save the default Record Type in hierarchical custom settings and add an If clause in VF.

IF New
   Show RecordType from Custom Setting
Else
   Show RecordType From The Record
| improve this answer | |

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.