+ Start a Discussion
Dustin SpitzDustin Spitz 

Dynamically assign child record types to parent objects (to URL hack or not to URL hack)

Hi , 

I was wondering if it's possible to dynamically assign record types of a child object based on a parent objects record type. 

Currently we use the case object to handle a lot of our business processes, and we are just starting to use custom objects. We provide different services such as warranties or exchanges, etc. for different parts, and these are handled through case record types. We recently created a master-detail relationship for a case part that allows the user to add multiple parts to a single case, but part information views will be different depending on the service we offer. 

What I'm looking for is if the user selected an exchange case record type, and added a new related list part instead of seeing part record types for warranties and exchanges, they would automatically open the part exchange record type. 

The only solution I've tried is creating custom buttons and modifying the URL (URL Hacking), but I've read this isn't a best practice, if there was a better way I'd love to learn how to do it. 

&RecordType= #######

Above is my URL Hack where CF... is the link to my Custom Object ID and RecordType is equal to the specific record type I want to display.

I just like to know best practices as I'm still learning.

I appreciate it, thanks!
Best Answer chosen by Dustin Spitz
Hi Dustin,

URL hacking is never recommended though it might help you achieve your requirement, even if you are going with this approach do not hardcode the ID's instead use JavaScript on the custom button to get the Record Type Id and redirect to the respective URL, below is an example JavaScript Code to get the Record Type Id:

{! REQUIRESCRIPT("/soap/ajax/34.0/connection.js")}
var recordtype= sforce.connection.query("select name, id from recordtype where name='XYZ'"); var records = recordtype.getArray("records");
var recordTypeId = records[0].Id;

Now a recommended solution to this would be to use Apex Trigger on Parts object to get the Case record type and set the Parts record type accordingly, you might however need to disable the option of chosing the record type for the Parts object as it is handled by the Trigger and the end user would not be given with an option of chosing the record type.

Below is a documentation which would help you start working with Triggers: