Ok, so I found the problem. It was in this line:
return new PageReference('/setup/ui/recordtypeselect.jsp?ent=Account&nooverride=1');
When I removed the override of the new button and tried to create a new Account, I saw this URL:
https://cs18.salesforce.com/setup/ui/recordtypeselect.jsp?ent=Account&retURL=%2F001%2Fo&save_new_url=%2F001%2Fe%3FretURL%3D%252F001%252Fo
Note this save_new_url parameter in there. After I added it to my PageReference
everything works as it is supposed to(some profiles get a custom VF page and others go to standard record type selection and standard new layout):
return new PageReference('/setup/ui/recordtypeselect.jsp?ent=Account&nooverride=1&save_new_url=%2F001%2Fe');
And actually I don't even need this if
anymore(that checks for RecordType parameter), so the code was reduced to this:
public PageReference redirect() {
if (!shouldSkipRecordTypeSelection(u)) { // a simple if that checks user's profile and returns true if record type selection should be skipped
return new PageReference('/setup/ui/recordtypeselect.jsp?ent=Account&nooverride=1&save_new_url=%2F001%2Fe');
}
return null;
}
EDIT
As sfdcweb mentioned is his comment, this will not work for custom objects by simple changing the ent property to MyCustomObject__c
.
To make it work for custom objects too you will have to use the 15 character id of that custom object. To find it, go to:
Then, just replace the ent=Account
with ent=01I8E0000008XjE
You can achieve this by creating three custom list buttons on the child object, one for each record type.
The content type of the button should be URL and the URL should look something like this.
/xxx/e?CF00ND000000xxxx={!X.Name}&CF00ND000000xxxx_lkid={!X.Id}&retURL=%2F{!Account.Id}&RecordTypeId='ChildRecordTypeId_R1'
Change the 'xxx' to key prefix of your custom object x and field Id 'CF00ND000000xxxx' field id of the lookup field x on your child object.
Create different page layouts for each recordtype in X. Expose the each of list of the child list button in each layout.
Hope this is helpful.
Best Answer
Currently, it's not possible select a record type in the createRecord component. You can create a dropdown or something with the record types options and then call the createRecord component passing the record type.
Example
This a dropdown example for select the record type
v.types is an array with the record types values