+ Start a Discussion
Semira@gmail.comSemira@gmail.com 

change record type of a child based of parent's value

Hi folks, 

I have a quick request. How would I go about chaning a record type of a child object depending on what the value of a picklist field on a parent object. 

This should be done by Visualforce page because I'm trying to overwrite the New button on the child object. So that users won't have to sleect the record type. 

Please help, this is a little urgent. 
Mohit Bansal6Mohit Bansal6
Semira

I think you are clicking new Button from Related list of child object under the parent object. Correct me, if i am wrong.

Follow below steps:
1. You can create a new Button on child object as a "list button".
2. Give name and label for button
3. Select Content Source: URL
4. In the formula window, 

/apex/name of page?RecordTypeID=value you want to set.

Regards
Mohit Bansal

Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Sanjay.GeorgeSanjay.George
The easiest Solution will be a 'before update, before insert' Trigger on child records.

You write a logic to query the parents List value and the Childs record type ID based on that.
 
for (Child__C CD: Trigger.new){
SetParent.add(CD.parent__C);
}

Map<id,Parent__c> MapidParent = new Map<id,Parent__c>([select id, listvalue from parent__C]);

for (Child__C CD: Trigger.new){
cd.recordTypeID = MapidParent.get(cd.Parent__c).ListValue=='Option1'?'<1REcordTypeID>':'<2REcordTypeID>';

}

 
Semira@gmail.comSemira@gmail.com
Mohit, 

New button does not allow you to write the formula or anything. It has to be Visualforce page. I am trying to overwrite the NEW button. 

Sanjay, 
Trigger only allows after you select the record type. I need to avoid having user to be able to select record type. 

So They click new, it takes them directly to edit page with the selected Record type depending on a value of a field in parent record.
Mohit Bansal6Mohit Bansal6
That's why I am saying....Inspite of overwriting salesforce standard button. Create your custom button and add it on page and remove standard new button from pagelayout. Regards Mohit Bansal
Semira@gmail.comSemira@gmail.com
Mohit, 

You can't add a custome button on a related list. Otherwise, I would have done that. I have tried creating a button and when I went to page layout to add the button on a related list, it doesn't give you any option. 
Mohit Bansal6Mohit Bansal6
Semira Clarify me one thing, you have two objects: A and B, and they both are linked via master Child relationship. A is master and B is child. If this is the scenario then I think you didn't read my message correctly. Please create a list button on child object which can be displayed on the related list of parent object. Regards Mohit Bansal
Semira@gmail.comSemira@gmail.com
My bad. They are lookup relationship, not master details. However, obj A(parent) is required in obj B (child). So you would go to obj A, scroll down to related list B and click create new record. 

Anyway, I think I found a way to overwrite the New button on obj B. but if you can find a way to create a button isntead, that's way better than coding.