function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
apex code shareapex code share 

Please help me writing a validation rule for record types.



I have a custom object SCHEME for which i have Record types standard and Additional and i have a picklist field TYPE(in both the record types) values in picklist field "TYPE":- 1> mechanics 2> reborer 3> mechanics + reborer


ON the scemes we have SCHEME LINE ITEMS related list. 


Which has record types: 1> mechanics 2> reborer 3> mechanics + reborer


So if i select the mechanics in the TYPE(picklist value in SCHEME) than the SCHEME LINE ITEMS record type for the reborer and mechanics + reborer should not be selected i.e only record type of scheme line item should be selected for which we have a picklist value in scheme.


Unless you override the new button and create a custom visualforce page to handle the record type selection based off of the chosen option on the parent, I do not believe you can controll what appears in the record type box of the standard select to this level of detail.....


You could use a validation rule, I guess, but you would be allowing your user to enter all of the data and then they will be told they have to go back and pick a different record type thus loosing all their data best practice IMHO.


Well, theoretically, you could easily create a custom button for the related list that chooses the requested record type automatically using a URL hack. (On the back end you might have to throw in a formula that returns text values of the record type id's, but that should work alot easier). Let me know if you need help. Good luck!

apex code shareapex code share



what i want now is if i select any record type in "SCHEME" ....than if i select new SCHEME LINE ITEMS should also reflect the same record type as of scheme.




Ok, now that is eaiser. Your first post sounded like there would be multiple options for a given recordtype.....


If there is only one recordtype of the child item (i.e. if Master = A then child always = B)


Here is a command button that I wrote to do just that:


<apex:commandButton styleclass="avoidMe"  value="New Account" title="Test" action="{!URLFOR($Action.Account.New, null,["p3" = "012A0000000gqsUIAQ","save"=1],true)}"/>

No you can convert this to anything you want. For me, it was used on a VF page. The styleClass was used to NOT hide the button as I had CSS hide all buttons ont he page to be able to hide the standard New button from salesforce in a list view.


The important part is the "p3" as that is the parameter for the recordtype. You can ad code to find the record type but in this case I just hardcoded it....(not best practice)


I hope this is a start for you...I am not the best at Javascript which is what you will have to convert this to in order to override the button without VF