One way to do it is to manually walk through the selection of a recordType then grabbing the URL from the Case landing page and identifying the parameters used there:
https://instance.salesforce.com/500/e?retURL=%2F001i0000002MX2z&def_account_id=001i0000002MX2z&RecordType=012i0000001ELIz&ent=Case
The example you have above is using p3 but I believe that is used for custom objects, you should be using RecordType instead.
Also, save=1 doesn't work without specifically asking SalesForce to disable a security feature, see docs here.
Here is a blog on another way of accomplishing this task using the url vs urlfor.
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
Best Answer
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.
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.