0

We have a custom object, say ABC__c, and it has 4 record types. Now, we have below two scenarios:

Scenario A:

  1. A User set the 'Set default record type' for this custom object ABC.

  2. User clicks on 'New' button to create new record.

  3. Page opened to create new record but URL does not include 'RecordType' parameter.

Scenario B:

  1. A normal user who has not set the default record type under my setting.

  2. User clicks on 'New' button to create new record. It opens the page to select record types out of 4 record types.

  3. Page opened to create new record and URL includes 'RecordType' parameter.

Now, our concern is why RecordType parameter is not there in URL for scenario A. Is it a salesforce bug?

How we can display the RecordType parameter in this case?

2
  • I don't know for certain how Salesforce, but I'd expect Salesforce would check to see whether or not that &RecordTypeId= parameter is there and if not, see what the default record type for that object is and set it as that. This wouldn't be a bug. When you say: "And How we can display the RecordType parameter in this case?", are you trying to display it in the URL?
    – Dan Jones
    Sep 12, 2016 at 13:46
  • Yes, I want to display the RecordType parameter in URL. So, that it behave in the same manner both ways.
    – Vijay Garg
    Sep 12, 2016 at 15:29

1 Answer 1

3

Assuming you're doing this in Visualforce, even though there's no RecordType parameter on the URL, you still know what record type it is. In an extension, you get it as the actual field value:

public MyController(ApexPages.StandardController ctrl) {
    Account rec = (Account)ctrl.getRecord();
    System.debug(reg.RecordTypeId);
}

You can also show it on the page using the standard controller:

{!Account.RecordType.Name}

In general, you should never depend on standard parameters like retURL, id, RecordType, and so on, because they're subject to change and/or be managed in different ways than you may expect. In all cases I can think of, there are ways to access standard parameters correctly. For example, retURL can be accessed via ctrl.cancel(), which returns a PageReference that essentially contains retURL, and saveURL can be accessed via ctrl.save(), which performs a DML and returns a PageReference on success.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .