Scenario : I have two objects Parent(Budget Header) and Child(Budget Child). There is a Checkbox field on Parent object 'Show Extended Budget' . There are 2 record types on Child object 'Normal Budget' and 'Extended Budget'.

Requirement : If the Show Extended Budget = FALSE then while creating Child record both the record types should show. And if Show Extended Budget = TRUE then only the 'Extended Budget' record type should show while creating the child records. Is it possible without creating a V.F Page ?

Solution Tried : I had created a formula field on Child object same as 'Show Extended Budget' on Parent object so that value from Parent is reflected to Child. Then I had created a workflow rule to change the record type of the Child record when the 'Show Extended Budget' became TRUE on Child. But this is not working since it is a formula field and is not triggering workflow rule.

Javascript code

var returnUrl = ''; 
if({!Master_Object__c.Checkbox_Field__c} == '1') 
returnUrl = "/<First 3 character of Child object Id>/e?retURL=%2F{!Master_Object__c.Id}&cancelURL=%2F{!Master_Object__c.Id}&RecordType=Child_Object_2nd_Recordtype_Id"; 
} else { 
returnUrl = "/setup/ui/recordtypeselect.jsp?ent=<Master_Object__Id>&retURL=%2F<Master_Object__c.ID>&save_new_url=%2Fa4a%2Fe%3FCF<Id of Lookup field on Child object to parent object>%3D{!Master_Object__c.Name}%26CF<Id of Lookup field on Child object to parent object>_lkid%3D{!Master_Object__c.Id}%26retURL%3D%252F{!Master_Object__c.Id}";
window.location.href = returnUrl;
  • How are you creating the child records? Is it by clicking the new button on the related list of Parent object? – Saroj Bera Jan 5 '17 at 10:48
  • Yes...as of now by clicking new button. – Ruchi Jan 5 '17 at 10:49

You can create an Onclick JavaScript List type button. Hide the default New button from the related list and add this new button. The button logic should be somewhat like below. Check the checkbox value, based on that either drive the user to the RecordType selection page or set the RecordType directly.

You can't change the dropdown values, so in one case show the RecordType Selection and in other case assign the RecordType. I hope this will work for you.

var returnUrl = '';
if (Master.checkbox == true) {
    returnUrl = "/setup/ui/recordtypeselect.jsp?ent=<Child Object 15 digit ID>&retURL=%2F{!Master.Id}&cancelURL=%2F{!Master.Id}";
} else {
    returnUrl = "/<First 3 Character>/e?retURL=%2F{!Master.Id}&cancelURL=%2F{!Master.Id}&RecordType=CHILD-RECORDTYPE_2";
window.location.href = returnUrl;

Update: Inside OnClick JS you will get the check box value as 0 or 1. So in actual code the Master.checkbox == true should look something like if('{!Metadata_Campaign__c.Parent_Checkbox__c}'=='1').

| improve this answer | |
  • this would be a sfdc Classic solution only, right? – cropredy Jan 6 '17 at 0:05
  • @cropredy yes this is a Salesforce classic solution. – Saroj Bera Jan 6 '17 at 5:12
  • @SarojBera : I have tried your solution but I am facing one issue. If I give IF condition as (Master.checkbox == true) then I am getting the error on clicking the new button as 'true is not defined' . If i give true in quotes then it is working for the 'FALSE' condition and not working for true condition. Means it is redirecting me to the page of 2nd record type even if the checkbox is true. – Ruchi Jan 9 '17 at 7:47
  • Is there any way to debug and check that what is the value of checkbox which the java script is taking ? – Ruchi Jan 9 '17 at 7:48
  • @Ruchi Yes you can use console.log() to print the values in JavaScript console. Check this link for details w3schools.com/js/js_output.asp – Saroj Bera Jan 9 '17 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.